<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
   <% String path=request.getContextPath(); 
   String basePath=request.getScheme()
    + "://" + request.getServerName() + ":" + request.getServerPort() + path
    + "/"; 

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml"> 

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<base href="<%=basePath%>">
<title>销售信息配置</title>
<jsp:include page="/WEB-INF/jsp/common/common.jsp"></jsp:include>
<link rel="stylesheet" href="<%=path%>/css/zTreeStyle/zTreeStyle.css">
<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
<style type="text/css">
#saveAppTable tr td{border-bottom:1px solid #A4BDE3;}
.inputborder{border-color: #ec8181;}
</style>
<script>
//自定义map功能
function Map(){
  this.elements = new Array();
   //获取MAP元素个数
   this.size = function() {
       return this.elements.length;
   };
   //判断MAP是否为空
   this.isEmpty = function() {
       return (this.elements.length < 1);
   };
   //删除MAP所有元素
   this.clear = function() {
       this.elements = new Array();
   };
   //向MAP中增加元素（key, value)
   this.put = function(_key, _value) {
       if(this.containsKey(_key)){
        this.remove(_key);
        this.elements.push( {
           key : _key,
           value : _value
        });
       }else{
        this.elements.push( {
           key : _key,
           value : _value
        });
       }  
   };
   //删除指定KEY的元素，成功返回True，失败返回False
   this.remove = function(_key) {
       var bln = false;
       try {
           for (var i = 0; i < this.elements.length; i++) {
               if (this.elements[i].key == _key) {
                   this.elements.splice(i, 1);
                   return true;
               }
           }
       } catch (e) {
           bln = false;
       }
       return bln;
   };
   //获取指定KEY的元素值VALUE，失败返回NULL
   this.get = function(_key) {
       try {
           for (var i = 0; i < this.elements.length; i++) {
               if (this.elements[i].key == _key) {
                   return this.elements[i].value;
               }
           }
       } catch (e) {
           return false;
       }
       return false;
   };
   //判断MAP中是否含有指定KEY的元素
   this.containsKey = function(_key) {
       var bln = false;
       try {
           for (var i = 0; i < this.elements.length; i++) {
               if (this.elements[i].key == _key) {
                   bln = true;
               }
           }
       } catch (e) {
           bln = false;
       }
       return bln;
   };
  //获取map的所有values
  this.values = function() {
       var arr = new Array();
       for (var i = 0; i < this.elements.length; i++) {
           arr.push(this.elements[i].value);
       }
       return arr;
   };
  //获取map的所有keys
  this.keys= function() {
       var arr = new Array();
       for (var i = 0; i < this.elements.length; i++) {
           arr.push(this.elements[i].key);
       }
       return arr;
   };
   //获取数组
   this.getArray= function(){
   	var arr = new Array();
   	for (var i = 0; i < this.elements.length; i++) {
           arr.push({
	            key : this.elements[i].key,
	            value : this.elements[i].value
	         });
       }
       return arr;
   };
}
//统一 关闭  窗口
function closeNocarAgentTypeDiv(obj){
	$("#"+obj).CloseDiv();	
}
//销售人员信息保存
function  saveSale(){
	var salemap1=new Map();
	var arr1 = new Array(); 
	for (var i = 1; i <= 5; i++) {
		var flag=0;
		var j=0;
		var o=new Object();
		var seqNo=$('#flag'+i).val();
		o.seqNo=seqNo;
		o.planType="2";
		//销售人员类别
		var saletype=$('#saletype'+i).val();
		var saleName=$('#saletype'+i).find("option:selected").text()
		if(saletype!='0'){
			o.saleType=saletype;
			o.saleName=saleName;
			j=j+1;
			flag=flag+1;
		}
		//费用比例
		var saleRate=$('#saleRate'+i).val();
		if($.trim(saleRate)!=''){
			o.agentFee=saleRate;
			j=j+1;
			flag=flag+1;
		}
		//执业证号
		var saleCallNo=$('#saleCallNo'+i).val();
		if($.trim(saleCallNo)!=''){
			o.practiceNo=saleCallNo;
		}
		//人员类别
		var saleMentype=$('#saleMentype'+i).val();
		var saleMenName= $('#saleMentype'+i).find("option:selected").text();
		if(saleMentype!='0'){
			o.personType=saleMentype;
			o.personTypeName=saleMenName;
			flag=flag+1;
			j=j+1;
		}
		//销售人员
		var saleMen=$('#saleMen'+i).val();
		if($.trim(saleMen)!=''){
			o.salePerson=saleMen;
			flag=flag+1;
		}
		//业务员
		var empNo=$('#empNo'+i).val();
		if($.trim(empNo)!=''){
			o.empNo=empNo;
			flag=flag+1;
			j=j+1;
		}
		//代理人编号
		var agentNo=$('#agentNo'+i).val();
		if($.trim(agentNo)!=''){
			o.agentNo=agentNo;
			flag=flag+1;
		}
		if(j>=1&&j!=4){
			$.message("error","财险销售信息配置序号为"+i+"的数据存在必填项未填写，请填写");
			return;			
		}
		if($.trim(saleRate)!=''){
			if(i!=1){
				var o1=salemap1.get(i-1);
				if(o1==null||o1==undefined||o1==false){
					$.message("error","财险销售信息配置序号为"+i+"的上一个序号未填写不能跳号");
					return;		
				}
			}
			salemap1.put(i,o);
			arr1.push(o);
		}
	}
	var rate=0;
	var isEmp=false;
	for (var i = 1; i <= 5; i++) {
		if(salemap1.get(i)){
			//比例校验 所有人员类别是业务员的比例之和是1，其他类别只能是0.
			if(salemap1.get(i).personType=='1'){
				if(salemap1.get(i).agentFee==''||salemap1.get(i).agentFee==undefined){
				}else{
					rate=parseFloat(rate)+parseFloat(salemap1.get(i).agentFee)
				}
				isEmp=true;
			}else{
				if(salemap1.get(i).agentFee!='0'){
					$.message("error","财险销售信息配置所有人员类别是业务员的比例之和是1，其他类别只能是0");
					salemap1.clear();
					return;	
				}
			}
		}
	}
	if(parseFloat(rate)!=1&&isEmp){
		$.message("error","财险销售信息配置所有人员类别是业务员的比例之和是1，其他类别只能是0");
		salemap1.clear();
		return;
	}

	var salemap2=new Map();
	var salemap3=new Map();
	for (var i = 1; i <= 5; i++) {
		var flag=0;
		var j=0;
		var o=new Object();
		o.planType="3";
		//职业证号
		var seqNo=$('#nflag'+i).val();
		o.seqNo=seqNo;
		var permitNo=$('#npermitNo'+i).val();
		if($.trim(permitNo)!=''){
			o.practiceNo=permitNo;
			flag=flag+1;
		}
		//销售人员类别
		var saleType=$('#nsaleMentype'+i).val();
		var saleTypeName= $('#nsaleMentype'+i).find("option:selected").text();
		if(saleType!=''){
			o.personType=saleType;
			j=j+1;
			flag=flag+1;
		}
		//销售人员代码
		var saleMen=$('#nsaleMen'+i).val();
		if($.trim(saleMen)!=''){
			o.empNo=saleMen;
			j=j+1;
			flag=flag+1;
		}
		//销售人员名称
		var saleName=$('#nsaleName'+i).val();
		if($.trim(saleName)!=''){
			o.saleName=saleName;
			flag=flag+1;
		}
		//费用比例
		var costRate=$('#ncostRate'+i).val();
		if($.trim(costRate)!=''){
			o.agentFee=costRate;
			j++;
			flag=flag+1;
		}
		//代理人机构号
		var agentCode=$('#nagentCode'+i).val();
		if($.trim(agentCode)!=''){
			o.agentCode=agentCode;
			flag=flag+1;
		}
		//代理人机构名称
		var agentName=$('#nagentName'+i).val();
		if($.trim(agentName)!=''){
			o.agentName=agentName;
			flag=flag+1;
		}
		if(j>=1&&j!=3){
			$.message("error","新意健险销售信息配置序号为"+i+"的数据存在必填项未填写，请填写");
			return;			
		}
		if($.trim(costRate)!=''){
			if(i!=1){
				var o1=salemap3.get(i-1);
				if(o1==null||o1==undefined||o1==false){
					$.message("error","新意健险销售信息配置序号为"+i+"的上一个序号未填写不能跳号");
					return;		
				}
			}
		}
		if($.trim(costRate)!=''){
			salemap3.put(i,o);
			arr1.push(o);
		}
	}
	var rate=0;
	for (var i = 1; i <= 5; i++) {
		if(salemap3.get(i).agentFee==''||salemap3.get(i).agentFee==undefined){
		}else{
			var rate1=salemap2.get(salemap3.get(i).personType);
			if(rate1){
				salemap2.put(salemap3.get(i).personType,parseFloat(salemap3.get(i).agentFee)+parseFloat(rate1));
			}else{
				salemap2.put(salemap3.get(i).personType,parseFloat(salemap3.get(i).agentFee));
			}
		}
	}
	if(salemap2){
		for(i in salemap2.keys()){
			var key = salemap2.keys()[i];
			if(salemap2.get(key)!="1"){
				$.message("error", "新意健险销售信息配置相同人员分摊比例之和是1");
				return;
			}
		}
	}
	var flag=true;
	$.openLoading();
	 var arr=JSON.stringify(arr1);
	var id= $('#agentId').val();
 	$.ajax({
		url : "<%=path%>/agentInfoMtManage/addTradSaleAgent",
		type : 'POST',
		async : true,
		data:{
			id:id,
			saleArry:arr
		},
		dataType:'json',
		success:function(result){
			$.closeLoading();
			if(result.result=='success'){
				closeNocarAgentTypeDiv('sale_div');
				$.message("success", "添加成功");
			}else{
				$.message("error", "添加失败");
			}
		}
	});
}
$(document).ready(function() {
	isReadyIframe();
	queryAgentMtInfo(1);
	$("#agentType_div").change(function(){
		  var resultCode = $("#agentType_div").val();
		  $("#partnerCode_tr").show();
			$('#unionType_tr').hide();
		  if(resultCode == '3'){
			  $('.userAgentMtInfo').show();
			  $('.branchAgentMtInfo').hide();
			  $("#userCode_div").next().show();
			  $("#userName_div").next().show();
			  $("#userCode_div").removeAttr("readonly");
			  $("#userCode_div").css("background","#fff");
			  $("#userName_div").removeAttr("readonly");
			  $("#userName_div").css("background","#fff");
			  $("#zone_div").val('');
			  $("#brach_div").val('');
			  $("#brachName_div").val('');
			  $('.userNameAgentMtInfo').show();
			  $('.nameAgentMtInfo').show();
			  $('.Key1AgentMtInfo').hide();
			  $('.Key2AgentMtInfo').hide();
			  $('.Key3AgentMtInfo').hide();
			  $('.Key4AgentMtInfo').hide();
			  $('.Key5AgentMtInfo').hide();
		  }else if(resultCode == '4'){
			  $('.userAgentMtInfo').hide();
			  $('.branchAgentMtInfo').show();
			  $("#userCode_div").attr("readonly","readonly");
			  $("#userCode_div").css("background","#ccc");
			  $("#userName_div").attr("readonly","readonly");
			  $("#userName_div").css("background","#ccc");
			  $("#userCode_div").next().hide();
			  $("#userName_div").next().hide();
			  $("#userCode_div").val('');
			  $("#userName_div").val('');
			  $("#subPartnerCode_div").val('');
			  $('.userNameAgentMtInfo').show();
			  $('.nameAgentMtInfo').show();
			  $('.Key1AgentMtInfo').hide();
			  $('.Key2AgentMtInfo').hide();
			  $('.Key3AgentMtInfo').hide();
			  $('.Key4AgentMtInfo').hide();
			  $('.Key5AgentMtInfo').hide();
		  }else if(resultCode == '5'){
			  $('.userAgentMtInfo').hide();
			  $('.branchAgentMtInfo').hide();
			  $("#userCode_div").attr("readonly","readonly");
			  $("#userCode_div").css("background","#ccc");
			  $("#userName_div").attr("readonly","readonly");
			  $("#userName_div").css("background","#ccc");
			  $("#userCode_div").next().hide();
			  $("#userName_div").next().hide();
			  $('.userNameAgentMtInfo').hide();
			  $('.nameAgentMtInfo').hide();
			  $('.Key1AgentMtInfo').show();
			  $('.Key2AgentMtInfo').show();
			  $('.Key3AgentMtInfo').show();
			  $('.Key4AgentMtInfo').show();
			  $('.Key5AgentMtInfo').show();
			  $('#unionType_tr').show();
			  $("#partnerCode_tr").hide();
		 }
	});
	
	//上传excel事件
	$("#buttonUpload").click(function(){
		$.openLoading();
		var fileNameStr = $('#fileToUpload').val();
		fileNameStr = fileNameStr+"";
		var lastDotIndex = fileNameStr.lastIndexOf(".");
		if(lastDotIndex==-1){
			$.closeLoading();
			$.message("error","请选择扩展名为 .xls 的文件上传");
			return;
		}else{
			var extName = fileNameStr.substring(lastDotIndex+1, fileNameStr.length);
			if(extName.toLowerCase() != "xls"){
				$.closeLoading();
				$.message("error","请选择扩展名为 .xls 的文件上传");
				return;
			}
		}
		$.ajaxFileUpload({
	        url:'<%=path%>/agentInfoMtManage/xlsImportAgentInfoFileUpload',
	        fileElementId :'fileToUpload',//file控件id
	        data:{agentType:'3'},
	        dataType: 'json',
	        success : function (data){
	        	$.closeLoading();
	        	if(data.result=="error"||data.result=="fail"){
	        		$.dialog({
		    			width: 358,
						height: 450,
		    			top:40,
		    			modal:true,
		    			Close:true,
		    			cancel:null,
		    			content: data.message
		    		});
					$(".xxDialog").css("overflow","scroll");
		        	return;
	        	}
	        	if($.validate(data)) return;
	        	queryAgentMtInfo(1);
	        }
		});
	});
	$("#auwConfigCheckAll").click(function(){
		if($(this).prop("checked")){//选中
			$("#planTable tbody tr").each(function() {
				$(this).find("input[name='checkPlan']").prop("checked",true);
				$(this).addClass("table_highlighter");
				var obj = new Object();
				var id= $(this).children(" td:eq(1)").html();
				obj.planNo =id;
				var commRate= $(this).children(" td:eq(4)").find('input').val();
				var busperRate= $(this).children(" td:eq(5)").find('input').val();
				var markperRate= $(this).children(" td:eq(6)").find('input').val();
				obj.commRate = commRate;
		    	obj.markperRate=markperRate;
		    	obj.busperRate=busperRate;
		    	planMap.put(id,obj);
			});
		}else{//取消选中
			$("#planTable tbody tr").each(function() {
				$(this).removeClass("table_highlighter");
				$(this).find("input[name='checkPlan']").prop("checked",false);
				var id= $(this).children(" td:eq(1)").html();
				planMap.remove(id);
			});
		}
	});
	//上传excel事件
	$("#buttonSubUpload").click(function(){
		$.openLoading();
		var fileNameStr = $('#fileToUploadBranch').val();
		fileNameStr = fileNameStr+"";
		var lastDotIndex = fileNameStr.lastIndexOf(".");
		if(lastDotIndex==-1){
			$.closeLoading();
			$.message("error","请选择扩展名为 .xls 的文件上传");
			return;
		}else{
			var extName = fileNameStr.substring(lastDotIndex+1, fileNameStr.length);
			if(extName.toLowerCase() != "xls"){
				$.closeLoading();
				$.message("error","请选择扩展名为 .xls 的文件上传");
				return;
			}
		}
		$.ajaxFileUpload({
	        url:'<%=path%>/agentInfoMtManage/xlsImportAgentInfoFileUpload',
	        fileElementId :'fileToUploadBranch',//file控件id
	        data:{agentType:'4'},
	        dataType: 'json',
	        success : function (data){
	        	$.closeLoading();
	        	if(data.result=="error"||data.result=="fail"){
		        	$.dialog({
		    			width: 358,
						height: 450,
		    			top:40,
		    			modal:true,
		    			Close:true,
		    			cancel:null,
		    			content: data.message
		    		});
					$(".xxDialog").css("overflow","scroll");
		        	return;
	        	}
	        	if($.validate(data)) return;
	        	queryAgentMtInfo(1);
	        }
		});
	});
	//代理类型change事件
	$("#agentType").change(function(){
		agentTypeChange();
	});
	//联合出单上传excel事件
	$("#buttonCombinedUpload").click(function(){
		$.openLoading();
		var fileNameStr = $('#fileToCombinedUpload').val();
		fileNameStr = fileNameStr+"";
		var lastDotIndex = fileNameStr.lastIndexOf(".");
		if(lastDotIndex==-1){
			$.closeLoading();
			$.message("error","请选择扩展名为 .xls 的文件上传");
			return;
		}else{
			var extName = fileNameStr.substring(lastDotIndex+1, fileNameStr.length);
			if(extName.toLowerCase() != "xls"){
				$.closeLoading();
				$.message("error","请选择扩展名为 .xls 的文件上传");
				return;
			}
		}
		$.ajaxFileUpload({
	      url:'<%=path%>/agentInfoMtManage/xlsImportAgentInfoFileUpload',
	      fileElementId :'fileToCombinedUpload',//file控件id
	      data:{agentType:'5'},
	      dataType: 'json',
	      success : function (data){
		    $.closeLoading();
	      	if(data.result=="error"||data.result=="fail"){
		        	$.dialog({
		    			width: 358,
						height: 450,
		    			top:40,
		    			modal:true,
		    			Close:true,
		    			cancel:null,
		    			content: data.message
		    		});
					$(".xxDialog").css("overflow","scroll");
		        	return;
	      	}
	      	if($.validate(data)) return;
	      	queryAgentMtInfo(1);
	      }
		});
	});
	agentTypeChange();
});
function agentTypeChange(){
	var agentType=$("#agentType").val();
	$('#channelCode_td').show();
	$('#channelCode_1').val('');
	$('#agentNo_td').hide();
	$('#agentNo_s').val('');
	$('#protocolNo_s').val('');
	$('#protocolNo_td').hide();
	if(agentType=='4'){
		$('#branch_td').show();
		$('#branchname_td').show()
		$('#userCode_td').hide();
		$('#username_td').hide()
		$('#userCode').val('');
		$('#userName').val('')
	}else if(agentType=='3'){
		$('#branch_s').val('');
		$('#branchName_s').val('');
		$('#userCode').val('');
		$('#userName').val('')
		$('#branch_td').hide();
		$('#branchname_td').hide()
		$('#userCode_td').show();
		$('#username_td').show()
	}else if(agentType=='5'){
		$('#userCode').val('');
		$('#userName').val('')
		$('#branch_s').val('');
		$('#branchName_s').val('');
		$('#branch_td').hide();
		$('#branchname_td').hide();
		$('#userCode_td').hide();
		$('#username_td').hide();
		$('#channelCode_td').hide();
		$('#agentNo_td').show();
		$('#protocolNo_td').show();
	}else{
		$('#userCode').val('');
		$('#userName').val('')
		$('#branch_s').val('');
		$('#branchName_s').val('');
		$('#branch_td').hide();
		$('#branchname_td').hide();
		$('#userCode_td').hide();
		$('#username_td').hide();
	}
}
function isReadyIframe(){
	var iframe = $(window.parent.document).find("#iframe").length;
	if(iframe==0){
		window.location.href="<%=path%>/index.jsp";
	}
}

//绑定单选按钮事件，选中某个单选按钮，该按钮所在行高亮显示
function bindradio(){
	$("input[name='partnerradio']").click(function(){
		$("input[name='partnerradio']").parent().parent().removeClass("table_highlighter");
		$(this).parent().parent().addClass("table_highlighter");
   	});
	$("input[name='deptradio']").click(function(){
		$("input[name='deptradio']").parent().parent().removeClass("table_highlighter");
		$(this).parent().parent().addClass("table_highlighter");
   	});
	$("input[name='subChannelInforadio']").click(function(){
		$("input[name='subChannelInforadio']").parent().parent().removeClass("table_highlighter");
		$(this).parent().parent().addClass("table_highlighter");
   	});
	$("input[name='checkPlan']").click(function(){
		var id= $(this).parent().parent().children(" td:eq(1)").html();
		var commRate= $(this).parent().parent().children(" td:eq(7)").find('input').val();
		var busperRate= $(this).parent().parent().children(" td:eq(8)").find('input').val();
		var markperRate= $(this).parent().parent().children(" td:eq(9)").find('input').val();
		if($(this).prop("checked")){//选中
			$(this).parent().parent().addClass("table_highlighter");
			var obj = new Object();
			obj.commRate = commRate;
			obj.planNo=id;
	    	obj.markperRate=markperRate;
	    	obj.busperRate=busperRate;
	    	planMap.put(id,obj);
	    	checkAll();
		}else{//取消选中
			$(this).parent().parent().removeClass("table_highlighter");
			$(this).prop("checked",false);
			planMap.remove(id);
			$("#auwConfigCheckAll").prop("checked",false);
		}
	});
}
function commRateChange(obj){
	var id= $(obj).parent().parent().children(" td:eq(1)").html();
	var o=planMap.get(id);
	if(o){
		var reg=/^0(\.\d{0,6})?$/;
		o.commRate= $(obj).val()+"";
		planMap.put(id,o);
	}
}
function markperRateChange(obj){
	if($(obj).parent().parent().children(" td:eq(0)").children("input[name='checkPlan']").prop("checked")){
		var id= $(obj).parent().parent().children(" td:eq(1)").html();
		var o=planMap.get(id);
		if(o){
			o.markperRate=$(obj).val()+"";
			planMap.put(id,o);
		}	
	}
}
function busperRateChange(obj){
	var id= $(obj).parent().parent().children(" td:eq(1)").html();
	var o=planMap.get(id);
	if(o){
		o.busperRate= $(obj).val()+"";
		planMap.put(id,o);
	}
}
//重置
function resetSearch(){
	$('#agentType').val("3");//默认为 个人代理类型
	$('#channelCode_1').val("");
	$('#userCode').val("");
	$('#userName').val("");
	$('#deptCode_s').val('');
	$('#empNo_s').val('');
	$('#branch_s').val('');
	$('#branchName_s').val('');
	agentTypeChange();
}
var rolemap=new Map();
//销售人员信息
function opensaleDiv(obj){
	var tempTr = $(obj).parent().parent()[0];
	var deptCode=tempTr.childNodes[10].innerHTML;
	var id=tempTr.childNodes[38].innerHTML;
	var sale=deptCode.substring(0,2);
	$('#agentId').val(id);
	if(sale=='44'){
		$.openLoading();
		$.ajax({
			url : "<%=path%>/agentInfoMtManage/loadSale",
			type : 'POST',
			async : true,
			data:{
				id:id
			},
			dataType:'json',
			success:function(data){
				$.closeLoading();
				if(data.success){
					rolemap.put("saleMenTypes", data.saleMenTypes);
					rolemap.put("saleTypes", data.saleTypes);
					rolemap.put("role", data.roleTypes);
					createSale(data.saleAgents);
				}else{
					$.message("error",data.message);
				}
			}
		});
	}else{
		$.message("error","非广东地区业务，无需进行费用跟单配置");
	}
}
var planNoMap=new Map();
/**方案配置*/
function openPlanDiv(obj){
	planNoMap.clear();
	planFeeReset();
	var tempTr = $(obj).parent().parent()[0];
	var id=tempTr.childNodes[38].innerHTML;
	$('#agentId').val(id);
	planMap.clear();
	planFeeParam(1);
}
function checkAll(){
	var flag = false;
	$("#planTable tbody").find("tr").each(function(){
		var id = $(this).children(" td:eq(1)").html();
		if(!$(this).children("td:eq(0)").find("input[name='checkPlan']").prop("checked")){
			flag = true;//如果有未选择的
		}
	});
	if(flag){
		$("#auwConfigCheckAll").prop("checked",false);
	}else{
		$("#auwConfigCheckAll").prop("checked",true);
	}
}
/**三费和**/
function totalRateSum(obj){
	var totalRate=0;
	if(obj.commRate!=''&&obj.commRate!=null&&obj.commRate!='null'){
		totalRate=totalRate+parseFloat(obj.commRate);
	}
	if(obj.markperRate!=''&&obj.markperRate!=null&&obj.markperRate!='null'){
		totalRate=totalRate+parseFloat(obj.markperRate);
	}
	if(obj.busperRate!=''&&obj.busperRate!=null&&obj.busperRate!='null'){
		totalRate=totalRate+parseFloat(obj.busperRate);
	}
	return totalRate;
}
/**方案配置保存*/
function choosePlanFee(){
	var planListStr ='';
	var planNosStr='';
	var agentInfoId=$('#agentId').val();
	if(!planMap.isEmpty()){
		var totalRate=0;
		var tradPlanlist = new Array();
		var tradPlanNo = new Array();
		for(i in planMap.keys()){
	        var key = planMap.keys()[i];
	        totalRate= totalRateSum(planMap.get(key));
	        var o=planMap.get(key);
	   		 var reg=/^0(\.\d{0,6})?$/;
		    if(o.commRate!=""&&o.commRate!=null&&o.commRate!="null"){
		        if(!reg.test(o.commRate)){
		        	$.message("error","手续费比例只能录入0到1之间的有效数字，方案号为"+key);
		        	return false; 
		        }
		    }
		    if(o.markperRate!=""&&o.markperRate!=null&&o.markperRate!="null"){
		        if(!reg.test(o.markperRate)){
		        	$.message("error","市场维护费比例只能录入0到1之间的有效数字，方案号为"+key);
		        	return false; 
		        }
		    }
		    if(o.busperRate!=""&&o.busperRate!=null&&o.busperRate!="null"){
		        if(!reg.test(o.busperRate)){
		        	$.message("error","业务绩效比例只能录入0到1之间的有效数字，方案号为"+key);
		        	return false; 
		        }
		    }
	        if(totalRate>=1){
				$.message("error","三费之和必须小于1，方案代码为‘"+key+"’的超出");
	        	return false; 
			}
	        tradPlanlist.push(planMap.get(key));
	    }
		if(!planNoMap.isEmpty()){
			for(i in planNoMap.keys()){
		        var key = planNoMap.keys()[i];
		       if(planNosStr==''){
		    	   planNosStr=key;
		       }else{
		    	   planNosStr+=","+key;
		       }
		    }		
		}
		planListStr=JSON.stringify(tradPlanlist);
		updatePlanConfig({planListStr:planListStr,agentInfoId:agentInfoId,planNosStr:planNosStr})
	}else{
		$.message("error", "请选择方案信息");
	}
}
//执行更新
function updatePlanConfig(param){
	$.openLoading();
	$.ajax({
		url : "<%=path%>/agentInfoMtManage/addTradPlanFee",
		type : 'POST',
		async : true,
		data:param,
		dataType:'json',
		success:function(data){
			$.closeLoading();
			if($.validate(data))return;
			$.message(data.result,data.message);
			if(data.result=="success"){
				closePlanDeptDiv();				
			}
		}
	});
}
/**方案配置参数*/
function planFeeParam(pageIndex){
	var size = 8;
	var planNo = $.trim($('#planNo').val());
	var planName = $.trim($('#planName').val());
	var deptCode=$.trim($('#deptCode_p').val());
	var agentInfoId=$('#agentId').val();
	loadPlanFee({size:size,current:pageIndex,planNo:planNo,planName:planName,deptCode:deptCode,agentInfoId:agentInfoId});
}
/**方案配置重置*/
function planFeeReset(){
	$("#planNo").val("");
	$("#planName").val("");
	$("#deptCode_p").val("00");
}
var planMap=new Map();
function loadPlanFee(param){
	$("#BigDiv3").remove();
	$.openLoading();
	$.ajax({
		url : "<%=path%>/agentInfoMtManage/loadPlanFee",
		type : 'POST',
		async : true,
		data:param,
		dataType:'json',
		success:function(data){
			$.closeLoading();
			if(data.data){
				$.each(data.data,function(i,item){
					if(item.AGENT_INFO_ID!=null){
						var obj = new Object();
						obj.planNo=item.PLAN_NO;
			        	obj.commRate = item.COMM_RATE;
			        	obj.markperRate=item.MARKPRE_RATE;
			        	obj.busperRate=item.BUSPER_RATE;
			        	planMap.put(item.PLAN_NO,obj);
			        	planNoMap.put(item.PLAN_NO, item.PLAN_NO);
					}
				})
			}
			var firstbutton="<input type='checkBox' value='' name='checkPlan' class='input_fxk'>";
			var lastbutton='<input type="text" value="" style="width:80px" name="commRate" onchange="commRateChange(this)"  name="txt3">@<input type="text" value="" style="width:80px" name="busperRate" onchange="busperRateChange(this)" name="txt3">@<input type="text" value="" name=" markperRate" onchange="markperRateChange(this)" name="txt3" style="width:100px">'
			var fieldNames = "PLAN_NO,PLAN_NAME,DEPT_ABR,CHANNEL_NAME,VHL_TYP,VHL_NLIFE_CAR";
			var tableContent = creatTable1(fieldNames,data,firstbutton,lastbutton);
			var tableObj = $("#planTable");
			tableObj.find("tbody").remove();
			tableObj.append(tableContent);
			var strPage = creatChannelPage2(param.current,6,data.maxPage,"70");
			var pageDIV = $("#planPageDIV");
			pageDIV[0].innerHTML="";
			pageDIV.append(strPage);
			//赋值
			if(!planMap.isEmpty()){
				$("input[name='checkPlan']").each(function() {
					 var planNo= $(this).parent().parent().children(" td:eq(1)").html();
					 if(planMap.get(planNo)){
						 $(this).prop("checked",true);
						 var commRate= $(this).parent().parent().children("td:eq(7)").find('input');
						 commRate.val(planMap.get(planNo).commRate);
						 var busperRate= $(this).parent().parent().children("td:eq(8)").find('input');
						 busperRate.val(planMap.get(planNo).busperRate);
						 var markperRate= $(this).parent().parent().children("td:eq(9)").find('input');
						 markperRate.val(planMap.get(planNo).markperRate);
						$(this).parent().parent().addClass("table_highlighter");
					 }
				});	
			}
			//全选
			var checkPlans=$("input[name='checkPlan']:checked");
			if(checkPlans.length==8){
				$("#auwConfigCheckAll").prop("checked",true);
			}else{
				$("#auwConfigCheckAll").prop("checked",false);
			} 
			$('#planDiv').OpenDiv3();
			bindradio();
			
		}
	});
}
function closePlanDeptDiv(){
	$('#planDiv').CloseDiv3();
}
/**广东销售*/
function createSale(agents){
	var salecontent=''
		for (var i = 1; i <= 5; i++) {
			salecontent+='<tr>'+
			'<td>'+i+'<input type="hidden" id="flag'+i+'" value="'+i+'"/></td>'+
			'<td>'+
				getSale1(i)+
			'</td>'+
			'<td><input type="text" onkeyup="clearNoNum(event,this)"  id="saleRate'+i+'" style=" width: 130px"/></td>'+							
			'<td><input type="text" id="saleCallNo'+i+'"  class="input_text" style=" width: 130px"/></td>'+								
			'<td>'+
				getSale(i)+
				'</select>'+
			'</td>'+
			'<td><input type="text" id="saleMen'+i+'"  class="input_text" style=" width: 130px"/></td>'+								
			'<td><input type="text" id="empNo'+i+'"  class="input_text" style=" width: 130px"/></td>'+							
			'<td><input type="text" id="agentNo'+i+'"  class="input_text" style=" width: 130px"/></td>'+								
		'</tr>'
		}
		$('#salecontent').html('');
		$('#salecontent').html(salecontent);
		/**加载新意健险界面*/
		createSale4(agents);
		$('#sale_div').OpenDiv()
		//赋值
		for (var i = 1; i <=agents.length; i++) {
		var o=agents[i-1];
		if(o&&o.planType==2){
			 $('#flag'+o.seqNo).val(o.seqNo);
			 $('#saletype'+o.seqNo).val(o.saleType);
			 $('#saleRate'+o.seqNo).val(Number(o.agentFee));
			 $('#saleCallNo'+o.seqNo).val(o.practiceNo);
			 $('#saleMentype'+o.seqNo).val(o.personType);
			 $('#saleMen'+o.seqNo).val(o.salePerson);
			 $('#empNo'+o.seqNo).val(o.empNo);
			 $('#agentNo'+o.seqNo).val(o.agentNo)
		}
	}
}
//跟单费用配置选择保存结束
function getSale4(i){
	var roles=rolemap.get("role");
	var hr='<select id="nsaleMentype'+i+'" class="select_1 valid" style=" width: 130px">'
			+'<option value="">请选择</option>'
		for (var j = 0; j < roles.length; j++) {
			hr+='<option value="'+roles[j].code+'">'+roles[j].codeName+'</option>'
		}
		hr+='</select>';
	return hr;
}
/**新意健险广东销售*/
function createSale4(agents){
	var salecontent=''
		for (var i = 1; i <= 5; i++) {
			salecontent+='<tr>'+
			'<td>'+i+'<input type="hidden" id="nflag'+i+'" value="'+i+'"/></td>'+
			'<td>'+
				getSale4(i)+
			'</td>'+
			'<td><input type="text" id="nsaleMen'+i+'"  class="input_text" style=" width: 130px"/></td>'+								
			'<td><input type="text" id="nsaleName'+i+'"  class="input_text" style=" width: 130px"/></td>'+	
			'<td><input type="text"  id="npermitNo'+i+'" style=" width: 130px"/></td>'+
			'<td><input type="text"  id="nagentCode'+i+'" style=" width: 130px"/></td>'+							
			'<td><input type="text" id="nagentName'+i+'"  class="input_text" style=" width: 130px"/></td>'+								
			'<td><input type="text" id="ncostRate'+i+'"  class="input_text" onkeyup="clearNoNum(event,this)" style=" width: 130px"/></td>'+								
		'</tr>'
		}
	$('#salecontent4').html('');
	$('#salecontent4').html(salecontent);
	//赋值
	for (var i = 1; i <=agents.length; i++) {
		var o=agents[i-1];
		if(o&&o.planType==3){
			 $('#nflag'+o.seqNo).val(o.seqNo);
			 $('#npermitNo'+o.seqNo).val(o.practiceNo);
			 $('#nagentCode'+o.seqNo).val(o.agentCode);
			 $('#nagentName'+o.seqNo).val(o.agentName);
			 $('#nsaleMentype'+o.seqNo).val(o.personType);
			 $('#nsaleMen'+o.seqNo).val(o.empNo);
			 $('#nsaleName'+o.seqNo).val(o.saleName);
			 $('#ncostRate'+o.seqNo).val(parseFloat(o.agentFee).toFixed(2))
		}
	} 
}
function getSale(i){
	var roles=rolemap.get("saleMenTypes");
	var hr='<select id="saleMentype'+i+'" class="select_1 valid" style=" width: 130px">'
			+'<option value="0">请选择</option>'
		for (var j = 0; j < roles.length; j++) {
			hr+='<option value="'+roles[j].code+'">'+roles[j].codeName+'</option>'
		}
		hr+='</select>';
	return hr;
}
function getSale1(i){
	var roles=rolemap.get("saleTypes");
	var hr='<select id="saletype'+i+'" class="select_1 valid" style=" width: 130px">'
			+'<option value="0">请选择</option>'
		for (var j = 0; j < roles.length; j++) {
			hr+='<option value="'+roles[j].code+'">'+roles[j].codeName+'</option>'
		}
		hr+='</select>';
	return hr;
}
/**
 * 页面初始化查询显示所有代理列表
 */
function queryAgentMtInfo(pageIndex){
	var uname = $('#userName').val();
	var channelCode = $('#channelCode_1').val();
	var userCode = $('#userCode').val();
	var agentType = $('#agentType').val();
	var branch=$('#branch_s').val();
	var branchName=$('#branchName_s').val();
	var dptCde=$('#deptCode_s').val();
	var empNo=$('#empNo_s').val();
	var agentNo=$('#agentNo_s').val();
	var protocolNo=$('#protocolNo_s').val();
	$.openLoading();
	$.ajax({
		url : "<%=path%>/agentInfoMtManage/queryByCriteria",
		type : 'POST',
		async : true,
		data:{"pageIndex":pageIndex,"userName":uname,"channelCode":channelCode,
			"userCode":userCode,"agentType":agentType,branch:branch,branchName:branchName,dptCde:dptCde,empNo:empNo,agentNo:agentNo,protocolNo:protocolNo},
		dataType:'json',
		success:function(userPage){
			$.closeLoading();
			if($.validate(userPage))return;
			//业务处理
				if(null != userPage){
					var buttonStr = '';
					if(agentType=='5'){
						buttonStr="<a href='javascript:void(0)'  onclick='openPlanDiv(this)'return false'>方案配置</a>&nbsp;";
					}
					 buttonStr += "<a href='javascript:void(0)'  onclick='opensaleDiv(this)'return false'>广东销售信息配置</a>&nbsp;<a href='javascript:void(0)' onClick='editAgentMtInfo(this);return false'>编辑</a>&nbsp;<a href='javascript:void(0)' onClick='delAgentMtInfo(this)'>删除</a>&nbsp;";
					var fieldNames = "AGENT_TYPE@TDH,CODE_NAME,USER_CODE,USER_NAME,UNION_TYPE@TDH,UNION_NAME,CHANNEL_CODE@TDH,CHANNEL_NAME,SUB_CHANNEL_CODE@TDH,BRANCH_NAME,DPT_CDE,CHANNLECODE@TDH,CHANNLECODEDES,CHANNLETYPE@TDH,CHANNLETYPEDES,NEWBSNSTYPE@TDH,NEWBSNSTYPEDES,CATEGORYCODE@TDH,CATEGORYCODEDES,AGENT_NO,PROTOCOL_NO,C_BRKR_NME,SERVICE_CODE,SERVICE_NAME,EMP_NO,EMP_NAME,CARD_APPLICANT,TEAM_CODE,C_OPR_CDE,key1,key2,key3,key4,key5,ORG_CODE,TEAM_NAME@TDH,ZONE@TDH,BRANCH@TDH,ID@TDH,TRANS_TYPE@TDH,C_AGENCY_CDE,C_PTCC_NUMBER,C_PHONE,C_EMPLO_YEE,C_BRKR_CERTF_CDE,C_SLS_IDENTITY_NO"; 					var tableContent = creatTable(fieldNames,userPage,buttonStr);
					var tableObj = $("#agentInfoTable");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					
					var strPage = creatChannelPage(pageIndex,6,userPage.maxPage,"28");
					var pageDIV = $("#agentInfoPageDIV");
					pageDIV[0].innerHTML="";
					pageDIV.append(strPage);
					
				}
		}
	});
}
var divLevel = "";
//打开 div 方法
function openThisDiv(divObj,pageIndex,cur,divCount){
	$("#"+cur.id).blur();
	$('#channelCode').val('');
	$('#channelName').val('');
	queryTradPartners(pageIndex,divLevel);
	divLevel = divCount;
}
//查询 投保单位
function queryTradPartners(pageIndex){
	mergePartnerParams(pageIndex);
}
//拼接页面查询参数  查询投保单位
function mergePartnerParams(pageIndex){
	var size = 8;
	var flag='';
	if(divLevel=='1'){
		flag='select'
	}
	var channelCode = $('#channelCode').val();
	var channelName = $('#channelName').val();
	queryPartner({pageIndex:pageIndex,size:size,channelCode:channelCode,channelName:channelName,flag:flag});
}
//initTradPartners
function queryPartner(param){
	$("#BigDiv2").remove();
	$.openLoading();
	$.ajax({
		url : "agentInfoMtManage/loadChannelInfo",
		type : 'POST',
		async : true,
		data:param,
		dataType:'json',
		success:function(partnerPage){
			$.closeLoading();
			if($.validate(partnerPage))return;

					var radioObj ="<input class='input_fxk' name='partnerradio' type='radio' value=''>";
					var fieldNames = "channelCode@TDH,channelCode,channelName,transType@TDH";
					var tableContent = creatTable1(fieldNames,partnerPage,radioObj);
					var tableObj = $("#TradPartnerTable");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					
					var strPage = creatChannelPage2(param.pageIndex,6,partnerPage.maxPage,"16");
					var pageDIV = $("#TradPartnerPageDIV");
					pageDIV[0].innerHTML="";
					pageDIV.append(strPage);
					if(divLevel=='1'){
						$('#tradPartnerDiv').OpenDiv();
					}else if(divLevel=='3'){
						$('#tradPartnerDiv').OpenDiv2();
					}
					
					bindradio();
			}
	});
	
}
var transType = "";//
//点击“确定”按钮，选择投保单位
function choosePartner(){
	var selectedPartner = $("input[name='partnerradio']:checked");
	if(selectedPartner.length==0){
		$.message("error", "请选择一个合作伙伴");
		return;
	}
	var pno = selectedPartner.parent().parent().children(" td:eq(1)").html();
	if('3' == divLevel){
		transType = selectedPartner.parent().parent().children(" td:eq(4)").html();
		$('#partnerCode_div').val(pno);
		$('#subPartnerCode_div').val('');
		$('#deptCode_div').val('');
		var temAgentCode_  = $('#agentType_div').val();
		if('4'== temAgentCode_ && '1' == transType){
			$("#userCode_div").removeAttr("readonly");
			$("#userCode_div").css("background","#fff");
			$("#userName_div").removeAttr("readonly");
			$("#userName_div").css("background","#fff");
		}else if('4'== temAgentCode_ && '2' == transType){
			$("#userCode_div").val('');
			$("#userName_div").val('');
			$("#userCode_div").attr("readonly","readonly");
		 	$("#userCode_div").css("background","#ccc");
			$("#userName_div").attr("readonly","readonly");
			$("#userName_div").css("background","#ccc");
		}
	}else if ('1' == divLevel){
		$('#deptCode_s').val('');
		$('#channelCode_1').val(pno);
	}
	inputBtn();
	closeCurrentDIV('tradPartnerDiv');
}
//关闭  窗口
function closeCurrentDIV(obj){
	if(('3' == divLevel && obj == 'tradPartnerDiv' ) || 'deptDiv' == obj || 'subTradPartnerDiv' == obj){
		$("#"+obj).CloseDiv2();
	}else{
		$("#"+obj).CloseDiv();
	}
	divLevel="";
}
//------------------------------------------ 合作伙伴子机构 开始----------------------------------------------
//打开机构窗口
function openSubChannelInfoDiv(pageIndex,obj){
	
	if($.trim($('#partnerCode_div').val()).length==0){
		$.message("error", "请先选择合作伙伴代码");
		return;
	}
	
	$('#subChannelCode').val('');
	$('#subChannelName').val('');
	$("#"+obj.id).blur();
	querySubChannelInfo(pageIndex);
}

//调用拼接参数的方法，并执行查询
function querySubChannelInfo(pageIndex){
	var size = 8;
	var code = $('#subChannelCode').val();
	var name = $('#subChannelName').val();
	var pno = $('#partnerCode_div').val();
	queryAllSubChannelInfo({size:size,pageIndex:pageIndex,subChannelCode:code,subChannelName:name,channelCode:pno});
}


//查询机构
function queryAllSubChannelInfo(param){
	$("#BigDiv2").remove();
	$.openLoading();
	$.ajax({
		url : "agentInfoMtManage/loadSubChannelInfo",
		type : 'POST',
		async : true,
		data:param,
		dataType:'json',
		success:function(deptPage){
			$.closeLoading();
			if($.validate(deptPage))return;

					var radioObj ="<input class='input_fxk' name='subChannelInforadio' type='radio' value=''>";
					var fieldNames = "SUBCHANNELCODE,SUBCHANNELNAME";
					var tableContent = creatTable1(fieldNames,deptPage,radioObj);
					var tableObj = $("#subTradPartnerTable");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					
					var strPage = creatChannelPage4(param.pageIndex,6,deptPage.maxPage,"29");
					var pageDIV = $("#subTradPartnerPageDIV");
					pageDIV[0].innerHTML="";
					pageDIV.append(strPage);
					
					$("#subTradPartnerDiv").OpenDiv2();
					
					bindradio();
			}
	});
}

//点击“确定” ，选择 出单机构
function chooseSubChannelInfo(){
	var selectedDept= $("input[name='subChannelInforadio']:checked");
	if(selectedDept.length==0){
		$.message("error", "请选择一个合作伙伴子机构");
		return;
	}
	var subChannelCode = selectedDept.parent().parent().children(" td:eq(1)").html();
	$('#subPartnerCode_div').val(subChannelCode);
	closeCurrentDIV('subTradPartnerDiv');
}


//------------------------------------------ 合作伙伴子机构 结束----------------------------------------------
//--查询出单机构
function closeSearchDeptDiv(){
	$("#deptDiv1").CloseDiv2();
}
//打开机构窗口
function openDeptDiv1(pageIndex,obj){
	$('#deptcode1').val('');
	$('#deptcnname1').val('');
	$("#"+obj.id).blur();
	queryCoreDept1(pageIndex);
}
//调用拼接参数的方法，并执行查询
function queryCoreDept1(pageIndex){
	var size = 8;
	var code = $('#deptcode1').val();
	var name = $('#deptcnname1').val();
	var pno = $('#channelCode_1').val();
	queryAllDepts1({size:size,current:pageIndex,deptCode:code,deptName:name,channelCode:pno});
}
//查询
function queryAllDepts1(param){
	$("#BigDiv2").remove();
	$.openLoading();
	$.ajax({
		url : "agentInfoMtManage/loadAgentDept",
		type : 'POST',
		async : true,
		data:param,
		dataType:'json',
		success:function(deptPage){
			$.closeLoading();
			if($.validate(deptPage))return;
			
					var radioObj ="<input class='input_fxk' name='deptradio' type='radio' value=''>";
					var fieldNames = "DEPT_CODE,DEPT_CNAME";
					var tableContent = creatTable1(fieldNames,deptPage,radioObj);
					var tableObj = $("#deptTable1");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					
					var strPage = creatChannelPage3(param.current,6,deptPage.maxPage,"65");
					var pageDIV = $("#deptPageDIV1");
					pageDIV[0].innerHTML="";
					pageDIV.append(strPage);
					
					$("#deptDiv1").OpenDiv2();
					
					bindradio();
			}
	});
}
//点击“确定” ，选择 出单机构
function chooseDept1(){
	var selectedDept= $("input[name='deptradio']:checked");
	if(selectedDept.length==0){
		$.message("error", "请选择一个出单机构");
		return;
	}
	var deptCode = selectedDept.parent().parent().children(" td:eq(1)").html();
	$('#deptCode_s').val(deptCode);
	closeSearchDeptDiv();
	}
//------------------------------------------ 出单机构 开始----------------------------------------------
//打开机构窗口
function openDeptDiv(pageIndex,obj){
	
	if($('#agentType_div').val()!='5'&&$.trim($('#partnerCode_div').val()).length==0){
		$.message("error", "请先选择合作伙伴代码");
		return;
	} 
	
	$('#deptcode').val('');
	$('#deptcnname').val('');
	$("#"+obj.id).blur();
	queryCoreDept(pageIndex);
}
//调用拼接参数的方法，并执行查询
function queryCoreDept(pageIndex){
	var size = 8;
	var code = $('#deptcode').val();
	var name = $('#deptcnname').val();
	var pno = $('#partnerCode_div').val();
	var agentType=$('#agentType_div').val();
	queryAllDepts({size:size,pageIndex:pageIndex,deptCode:code,deptCNname:name,channelCode:pno,agentType:agentType});
}


//查询机构
function queryAllDepts(param){
	$("#BigDiv2").remove();
	$.openLoading();
	$.ajax({
		url : "agentInfoMtManage/loadCoreDept",
		type : 'POST',
		async : true,
		data:param,
		dataType:'json',
		success:function(deptPage){
			$.closeLoading();
			if($.validate(deptPage))return;

					var radioObj ="<input class='input_fxk' name='deptradio' type='radio' value=''>";
					var fieldNames = "deptCode,deptCNname";
					var tableContent = creatTable1(fieldNames,deptPage,radioObj);
					var tableObj = $("#deptTable");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					
					var strPage = creatChannelPage3(param.pageIndex,6,deptPage.maxPage,"18");
					var pageDIV = $("#deptPageDIV");
					pageDIV[0].innerHTML="";
					pageDIV.append(strPage);
					
					$("#deptDiv").OpenDiv2();
					
					bindradio();
			}
	});
}

//点击“确定” ，选择 出单机构
function chooseDept(){
	var selectedDept= $("input[name='deptradio']:checked");
	if(selectedDept.length==0){
		$.message("error", "请选择一个出单机构");
		return;
	}
	var deptCode = selectedDept.parent().parent().children(" td:eq(1)").html();
	$('#deptCode_div').val(deptCode);
	closeCurrentDIV('deptDiv');
	querySauserAndTeamInfo('');
}

//获取业务员信息及业务员所在团队信息
var team_user_list;//存放销管返回的业务员及团队信息的List,便于业务员代码改变时，业务员名称和团队列表的同步改变
function querySauserAndTeamInfo(tempTr){
	var dptCde = $.trim($('#deptCode_div').val());
	//必须先选择出单机构，再获取
	if(dptCde.length==0){
		$.message('error',"请先选择出单机构");
		return;
	}
	$.openLoading();
	$.ajax({
		url : "<%=path%>/agentInfoMtManage/querySauserAndTeamInfo?"+new Date().getTime(),
		type : 'POST',
		async : true,
		data:{
			COMCODE:dptCde
		},
		dataType:'json',
		success:function(result){
			$.closeLoading();
			var select = document.getElementById("empNo_select");
			select.options.length = 0;
			select.add(new Option("-----请选择-----",""));
			team_user_list = result.data;
	 		var empNo = $.trim($("#empNo").val());
	 		if(null != team_user_list){
	 			for (var i = 0; i < team_user_list.length; i++) {
					var option = new Option();
					option.text = team_user_list[i].USERCODE + "-" + team_user_list[i].USERNAME;
					option.title = team_user_list[i].USERCODE + "-" + team_user_list[i].USERNAME;
					option.value = team_user_list[i].USERCODE;
					if(empNo == team_user_list[i].USERCODE){
						option.selected=true;	
						$("#empName_div").val(team_user_list[i].USERNAME);
						$('#empNo_select_div').css('display','inline').val("");
						$('#empNo_div').hide().val(team_user_list[i].USERCODE);
					}else if(empNo.length<1){
						$('#empNo_select_div').css('display','inline').val("");
						$('#empNo_div').hide().val('');
					}
					select.add(option);
				}
	 		}
	 		if('' != tempTr){
	 			var emoValList = $("#empNo_select option");
	 			var empNo = tempTr.childNodes[24].innerHTML;
	 			var empName = tempTr.childNodes[25].innerHTML;
	 			var empFlag =false;
	 			for(var i = 0;i < emoValList.length;i++){
 					console.log(empNo+"-"+empName +"============"+ emoValList[i].title);
	 				if(empNo+"-"+empName == emoValList[i].title){
	 					empFlag =true;
	 				}
	 			}
	 			console.log(empFlag);
	 			if(empFlag){
	 				$("#empNo_select").val(empNo);
	 			}else{
	 				empInfoWrite();
	 			}
	 			$("#empNo_div").val(empNo);
	 			$("#empName_div").val(empName);
	 		}
		}
	});
}

//业务员下拉框改变时，动态改变业务员名称和团队代码
var TEAMList;//存放当前所选业务员对应的团队List，便于团队代码改变时，团队名称的同步改变
function changeEmpNo(){
	var dptCde = $.trim($('#deptCode_div').val());
	var channleCode_QD = $.trim($('#channelCodeQD').val());
	var newBsnsType =$.trim($('#newBsnsType').val());
	//必须先选择出单机构、归属渠道、业务来源,再获取
	if(dptCde.length == 0){
		$("#empNo_select").find("option[value='']").attr("selected",true);
		$.message('error',"请选择出单机构");
		return;
	}
	if(channleCode_QD.length == 0){
		$("#empNo_select").find("option[value='']").attr("selected",true);
		$.message('error',"请选择归属渠道");
		return;
	}
	if(newBsnsType.length == 0){
		$("#empNo_select").find("option[value='']").attr("selected",true);
		$.message('error',"请选择业务来源");
		return;
	}
	var empNo_select = $.trim($("#empNo_select").val());
	if (empNo_select.length > 10) {
		$.message('error', "业务员代码长度不能超过10位！");
		return;
	}
	$("#empNo_div").val(empNo_select);
	if(empNo_select.length == 0) {
		$("#empName_div").val("");
		teamInfoWrite();
		return;
	}
	if(null != team_user_list){
		for (var i = 0; i < team_user_list.length; i++) {
			var USERCODE = team_user_list[i].USERCODE;
			if(empNo_select == USERCODE){
				$("#empName_div").val(team_user_list[i].USERNAME);
				TEAMList = team_user_list[i].TEAMList;
				var select = document.getElementById("teamCode_select");
				select.options.length = 0;
				select.add(new Option("-----请选择-----",""));
				if(null != TEAMList){
					for (var j = 0; j < TEAMList.length; j++) {
						var option = new Option();
						option.text = TEAMList[j].TEAMCODE + "-" + TEAMList[j].TEAMNAME;
						option.title = TEAMList[j].TEAMCODE + "-" + TEAMList[j].TEAMNAME;
						option.value = TEAMList[j].TEAMCODE;
						select.add(option);
					}
				}
				teamInfoSelect();
				return;
			}
		}
	}
}

//团队代码改变时，动态改变团队名称
function changeTeamCode(){
	var teamCode_select = $.trim($("#teamCode_select").val());
	var teamCode = $.trim($("#teamCode_div").val());
	if (teamCode_select.length > 11) {
		$.message('error', "团队代码长度不能超过11位！");
		return;
	}
	$("#teamCode_div").val(teamCode_select);
	if(teamCode_select.length==0) {
		$("#teamName_div").val("");
		return;
	}
	if(null != TEAMList){
		for (var i = 0; i < TEAMList.length; i++) {
			var TEAMCODE = TEAMList[i].TEAMCODE;
			if(teamCode_select == TEAMCODE){
				$("#teamName_div").val(TEAMList[i].TEAMNAME);
			}
		}
	}
}

//团队代码可选状态
function teamInfoSelect(){
	$('#teamCode_select_div').css('display','inline').val("");
	$('#teamCode_div').hide().val('');
	$('#teamName_div').attr("readonly",true).css('background-color','#ccc').val("");
}

//团队代码、团队名称可输入状态
function teamInfoWrite(){
	$('#teamCode_select_div').css('display','none').val("");
	$('#teamCode_div').show().val('');
	$('#teamName_div').attr("readonly",false).css('background-color','white').val('');
}

//业务员代码、业务员名称可输入状态
function empInfoWrite(){
	$('#empNo_select_div').css('display','none').val("");
	$('#empNo_div').show().val('');
	$('#empName_div').attr("readonly",false).css('background-color','white').val('');
}

//手动录入
function inputBtn(){
	empInfoWrite();
	teamInfoWrite();
}

//------------------------------------------ 出单机构 结束----------------------------------------------
//点击"新增"(弹出层)
var handleFlag="";
function addAgentInfo(){
	$('#unionType_tr').hide();
	var resultCode = $("#agentType").val();
	$("#agentType_div").val(resultCode);
	$("#unionType_div").val('');
	$("#partnerCode_tr").show();
	if(resultCode == '3'){
		  $('.userAgentMtInfo').show();
		  $('.branchAgentMtInfo').hide();
		  //
		  $("#userCode_div").removeAttr("readonly");
		  $("#userCode_div").css("background","#fff");
		  $("#userName_div").removeAttr("readonly");
		  $("#userName_div").css("background","#fff");
		  $("#userCode_div").next().show();
		  $("#userName_div").next().show();
		  $('.userNameAgentMtInfo').show();
		  $('.nameAgentMtInfo').show();
		  $('.Key1AgentMtInfo').hide();
		  $('.Key2AgentMtInfo').hide();
		  $('.Key3AgentMtInfo').hide();
		  $('.Key4AgentMtInfo').hide();
		  $('.Key5AgentMtInfo').hide();
	  }else if(resultCode == '4'){
		  $('.userAgentMtInfo').hide();
		  $('.branchAgentMtInfo').show();
		  //
		  $("#userCode_div").attr("readonly","readonly");
		  $("#userCode_div").css("background","#ccc");
		  $("#userName_div").attr("readonly","readonly");
		  $("#userName_div").css("background","#ccc");
		  $("#userCode_div").next().hide();
		  $("#userName_div").next().hide();
		  $('.userNameAgentMtInfo').show();
		  $('.nameAgentMtInfo').show();
		  $('.Key1AgentMtInfo').hide();
		  $('.Key2AgentMtInfo').hide();
		  $('.Key3AgentMtInfo').hide();
		  $('.Key4AgentMtInfo').hide();
		  $('.Key5AgentMtInfo').hide();
	 }else if(resultCode == '5'){
		 $('.userAgentMtInfo').hide();
		  $('.branchAgentMtInfo').hide();
		  $("#userCode_div").attr("readonly","readonly");
		  $("#userCode_div").css("background","#ccc");
		  $("#userName_div").attr("readonly","readonly");
		  $("#userName_div").css("background","#ccc");
		  $("#userCode_div").next().hide();
		  $("#userName_div").next().hide();
		  $('.userNameAgentMtInfo').hide();
		  $('#unionType_tr').show();
		  $('.nameAgentMtInfo').hide();
		  $('.Key1AgentMtInfo').show();
		  $('.Key2AgentMtInfo').show();
		  $('.Key3AgentMtInfo').show();
		  $('.Key4AgentMtInfo').show();
		  $('.Key5AgentMtInfo').show();
		  $("#partnerCode_tr").hide();
	 }
	$('#searchPartnerBtn2Code').show();
	handleFlag="save";
	$("#addOrUpdateDiv").OpenDiv();
}

//隐藏 addOrUpdateDiv
function closeAddOrUpdateDiv(){
	handleFlag="";
	agentTypeFlag="";
	uId="";
	transType="";
	$("body").attr("style", "overflow:scroll");
	$("#addOrUpdateDiv").CloseDiv();
	$("#agentType_div").val('');
	$("#channelCodeQD").val('');
	$("#channelType").val('');
	$("#newBsnsType").val('');
	$("#bsnsType").val('');
 	$("#addOrUpdateDiv input[type !='button']").val('');
	$("#agentType_div").removeAttr("disabled");
	$("#userCode_div").removeAttr("readonly");
	$("#userCode_div").css("background","#fff");
	$("#userName_div").removeAttr("readonly");
	$("#userName_div").css("background","#fff");
	$("#zone_div").removeAttr("readonly");
	$("#zone_div").css("background","#fff");
	$("#branch_div").removeAttr("readonly");
	$("#branch_div").css("background","#fff");
/* 	location.reload(false); 
 */}

//key1~key5校验
function checkKey(key1,key2,key3,key4,key5){
	//1.校验key1,key2非空，
	var primeKey = true;
	if(key1.length == 0){
		keyAddClass("pro_key1");
		$.message("error", "请输入Key1");
		primeKey = false;
	}
	if(key2.length == 0 && primeKey){
		$.message("error", "请输入Key2");
		keyAddClass("pro_key2");
		primeKey = false;
	}
/* 	if(primeKey){
		//2.校验key3 、key4和key5
		if(key3.length == 0 && key4.length != 0){
			keyAddClass("pro_key3");
			$.message("error", "请输入Key3");
			primeKey = false;
		}
		if(key4.length == 0 && key5.length != 0){
			keyAddClass("pro_key4");
			$.message("error", "请输入Key4");
			primeKey = false;
		}
		if(key3.length == 0 && key4.length == 0 && key5.length != 0){
			keyAddClass("pro_key3");
			keyAddClass("pro_key4");
			$.message("error", "请输入key3、Key4");
			primeKey = false;
		}
	} */
	return primeKey;
}
//为空输入框提示
function keyAddClass(keyId){
	var key = $("#"+keyId);
	var keyf = key.parent();
	key.addClass("inputborder");
	key.one("focus",function(){
		key.removeClass("inputborder");
	});
}

function saveAgentMtInfo(){
	var curunt=$('#switchPage').val();
	var agentType = $.trim($("#agentType_div").val());
	var userCode = $.trim($("#userCode_div").val());
	var userName = $.trim($("#userName_div").val());
	var dptCde = $.trim($("#deptCode_div").val());
	var channelCode = $.trim($("#partnerCode_div").val());
	var subChannelCode = $.trim($("#subPartnerCode_div").val());
	var agentNo = $.trim($("#agentNo_div").val());
	var protocolNo = $.trim($("#protocolNo_div").val());
	var serviceCode = $.trim($("#serviceCode_div").val());
	var serviceName = $.trim($("#serviceName_div").val());
	var empNo = $.trim($("#empNo_div").val());
	var empName = $.trim($("#empName_div").val());
	var teamCode = $.trim($("#teamCode_div").val());
	var teamName = $.trim($("#teamName_div").val());
	var zone = $.trim($("#zone_div").val());
	var organization = $.trim($("#organization_div").val());
	var branch = $.trim($("#branch_div").val());
	var branchName = $.trim($("#branchName_div").val());
	var cardApplicant = $.trim($("#cardApplicant_div").val());
	var channle_code = $.trim($('#channelCodeQD').val());
	var channle_type = $.trim($('#channelType').val());
	var newBsns = $.trim($('#newBsnsType').val());
	var categoryCode = $.trim($('#bsnsType').val());
	var cbrkrname = $.trim($("#cbrkrname_div").val());
	var coprcod = $.trim($("#coprcod_div").val());
	var key1 = $.trim($("#pro_key1").val());
	var key2 = $.trim($("#pro_key2").val());
	var key3 = $.trim($("#pro_key3").val());
	var key4 = $.trim($("#pro_key4").val());
	var key5 = $.trim($("#pro_key5").val());
	var unionType=$("#unionType_div").val();
	if(dptCde.length == 0){
		$.message("error", "请选择出单机构");
		return;
	}
	if(agentType.length == 0){
		$.message("error", "请选择销售类型");
		return;
	}
	if('5'!= agentType ){
		if(channelCode.length == 0){
			$.message("error", "请选择合作伙伴");
			return;
		}
		unionType='';
	}else{
		if(unionType.length == 0){
			$.message("error", "请选择联合出单方案");
			return;
		}
		channelCode='';
	}
	
	var reg = new RegExp("^[A-Za-z0-9_]+$");
	if('3'== agentType){
		if(userCode.length == 0){
			$.message("error", "请输入用户名");
			return;
		}
		if(!(reg.test(userCode))){
			$.message("error", "输入的用户名格式不正确,正确格式只能录入字母、数字、下划线组合的字符串");
			return;
		}
		if(userName.length == 0){
			$.message("error", "请输入姓名");
			return;
		}
	}
	<%-- 加入总对总界面出单类型判断 --%>
	if('4'== agentType && '1'== transType){
		if(userCode.length == 0 && userName.length != 0){
			$.message("error", "请输入用户名");
			return;
		}else if(userCode.length != 0 && userName.length == 0){
			$.message("error", "请输入姓名");
			return;
		}else if(userCode.length != 0 && userName.length != 0){
			if(!(reg.test(userCode))){
				$.message("error", "输入的用户名格式不正确,正确格式只能录入字母、数字、下划线组合的字符串");
				return;
			}
		}
	}
	if('4'== agentType){
		if((zone.length > 0) && !(reg.test(zone))){
			$.message("error", "输入的区域代码格式不正确，正确格式只能录入数字、字母、下划线组合的字符");
			return;
		}
		if((organization.length > 0) && !(reg.test(organization))){
			$.message("error", "输入的组织机构代码格式不正确，正确格式只能录入数字、字母组合的字符");
			return;
		}
		if(branch.length == 0){
			$.message("error", "请输入网点代码");
			return;
		}
		if(!(reg.test(branch))){
			$.message("error", "输入的网点代码格式不正确，正确格式只能录入数字、字母、下划线组合的字符");
			return;
		}
		if(branchName.length == 0){
			$.message("error", "请输入网点名称");
			return;
		}
	}
	
	if(channle_code.length==0){
		$.message("error", "请选择归属渠道");
		$('#channelCodeQD').focus();
		return;
	}
	
	if(channle_type.length==0){
		$.message("error", "请选择渠道类型");
		$('#channelType').focus();
		return;
	}
	
	if(newBsns.length==0){
		$.message("error", "请选择新业务来源");
		$('#newBsnsType').focus();
		return;
	}
	
	if(categoryCode.length==0){
		$.message("error", "请选择原业务来源");
		$('#bsnsType').focus();
		return;
	}
	if(categoryCode=="19002"||categoryCode=="19003"){
		if(agentNo.length == 0){
			$.message("error", "请输入代理人编码");
			return;
		}else if(protocolNo.length == 0){
			$.message("error", "请输入代理人协议号");
			return;
		}else if(cbrkrname.length == 0){
			$.message("error", "请输入代理人名称");
			return;
		}
	}
	if(serviceCode.length == 0){
		if(agentType == '5'){
			keyAddClass("serviceCode_div");
		}
		$.message("error", "请输入服务代码");
		return;
	}
	if(empNo.length == 0){
		if(agentType == '5'){
			keyAddClass("empNo_div");
		}
		$.message("error", "请输入业务员代码");
		return;
	}
	if(empName.length == 0){
		if(agentType == '5'){
			keyAddClass("empName_div");
		}
		$.message("error", "请输入业务员名称");
		return;
	}
	if(teamCode.length == 0){
		if(agentType == '5'){
			keyAddClass("teamCode_div");
		}
		$.message("error", "请输入团队代码");
		return;
	}
	if(teamName.length == 0){
		if(agentType == '5'){
			keyAddClass("teamName_div");
		}
		$.message("error", "请输入团队名称");
		return;
	}
	
	//销售类型是联合出单:key1~key5校验
	if(agentType == '5'){
		var primeKey = checkKey(key1,key2,key3,key4,key5);
		if(!primeKey) return;
	}
	
	//
	if('update' == handleFlag){
		agentType = agentTypeFlag;
		var id =uId;
	}

	$.openLoading();
	$.ajax({
		url : "<%=path%>/agentInfoMtManage/saveAgentMtInfo?"+new Date().getTime(),
		type : 'POST',
		async : true,
		data:{
			id:id,
			agentType:agentType,
			userCode:userCode,
			userName:userName,
			channelCode:channelCode,
			subChannelCode:subChannelCode,
			dptCde:dptCde,
			zone:zone,
			organization:organization,
			branch:branch,
			branchName:branchName,
			agentNo:agentNo,
			protocolNo:protocolNo,
			serviceCode:serviceCode,
			serviceName:serviceName,
			empNo:empNo,
			empName:empName,
			teamCode:teamCode,
			teamName:teamName,
			cardApplicant:cardApplicant,
			channleCode:channle_code,
			channleType:channle_type,
			newBsnsType:newBsns,
			categoryCode:categoryCode,
			flag:handleFlag,
			cbrkrname:cbrkrname,
			coprcod:coprcod,
			key1:key1,
			key2:key2,
			key3:key3,
			key4:key4,
			key5:key5,
			unionType:unionType
		},
		dataType:'json',
		success : function(data) {
			$.closeLoading();
			if($.validate(data))  return;
			if(curunt==undefined){
				curunt=1;
			}
			queryAgentMtInfo(curunt);
			closeAddOrUpdateDiv();
		}
	});
}
var agentTypeFlag="";
var uId="";
function editAgentMtInfo(obj){
	$('#unionType_div').val('')
	handleFlag="update";
	var tempTr = $(obj).parent().parent()[0];
		agentTypeFlag = tempTr.childNodes[0].innerHTML;
	var userCode = tempTr.childNodes[2].innerHTML;
	var UserName = tempTr.childNodes[3].innerHTML;
	var unionType=tempTr.childNodes[4].innerHTML;
	var channelCode = tempTr.childNodes[6].innerHTML;
	var subChannelCode = tempTr.childNodes[8].innerHTML;
	var branchName = tempTr.childNodes[9].innerHTML;
	var deptCode = tempTr.childNodes[10].innerHTML;
	
	var channleCode=tempTr.childNodes[11].innerHTML;
	var channleType=tempTr.childNodes[13].innerHTML;
	var newBsnsType=tempTr.childNodes[15].innerHTML;
	var categoryCode=tempTr.childNodes[17].innerHTML;
	
	var agentNo = tempTr.childNodes[19].innerHTML;
	var protocolNo = tempTr.childNodes[20].innerHTML;
	var cbrkrname = tempTr.childNodes[21].innerHTML;
	var serviceCode = tempTr.childNodes[22].innerHTML;
	var serviceName = tempTr.childNodes[23].innerHTML;
	var empNo = tempTr.childNodes[24].innerHTML;
	var empName = tempTr.childNodes[25].innerHTML;
	var cardApplicant = tempTr.childNodes[26].innerHTML;
	var teamCode = tempTr.childNodes[27].innerHTML;
	var coprcod = tempTr.childNodes[28].innerHTML;
	var key1 = tempTr.childNodes[29].innerHTML;
	var key2 = tempTr.childNodes[30].innerHTML;
	var key3 = tempTr.childNodes[31].innerHTML;
	var key4 = tempTr.childNodes[32].innerHTML;
	var key5 = tempTr.childNodes[33].innerHTML;
	var organization = tempTr.childNodes[34].innerHTML;
	var teamName = tempTr.childNodes[35].innerHTML;
	var zone = tempTr.childNodes[36].innerHTML;
	var branch = tempTr.childNodes[37].innerHTML;
	uId = tempTr.childNodes[38].innerHTML;
	transType = tempTr.childNodes[39].innerHTML;

	//
	$("#agentType_div").val(agentTypeFlag);
	$("#agentType_div").attr("disabled","disabled");
	$("#userCode_div").val(userCode);
	$("#userCode_div").attr("readonly","readonly");
	$("#userCode_div").css("background","#ccc");
	$("#userName_div").val(UserName);
// 	$("#userName_div").attr("readonly","readonly");
// 	$("#userName_div").css("background","#ccc");
	$("#deptCode_div").val(deptCode);
	$("#partnerCode_div").val(channelCode);
	$("#subPartnerCode_div").val(subChannelCode);
	$("#agentNo_div").val(agentNo);
	$("#protocolNo_div").val(protocolNo);
	$("#serviceCode_div").val(serviceCode);
	$("#serviceName_div").val(serviceName);
	$("#empNo_div").val(empNo);
	$("#empName_div").val(empName);
	$("#cbrkrname_div").val(cbrkrname);
	$("#coprcod_div").val(coprcod);
	$("#teamCode_div").val(teamCode);
	$("#teamName_div").val(teamName);
	$("#zone_div").val(zone);
	$("#organization_div").val(organization);
	$("#zone_div").attr("readonly","readonly");
	$("#zone_div").css("background","#ccc");
	$("#branch_div").val(branch);
	$("#branch_div").attr("readonly","readonly");
	$("#branch_div").css("background","#ccc");
	$("#branchName_div").val(branchName);
	$("#cardApplicant_div").val(cardApplicant);
	$('#channelCodeQD').val(channleCode);
	$('#channelType').val(channleType);
	$('#newBsnsType').val(newBsnsType);
	$('#bsnsType').val(categoryCode);
	$('#pro_key1').val(key1);
	$('#pro_key2').val(key2);
	$('#pro_key3').val(key3);
	$('#pro_key4').val(key4);
	$('#pro_key5').val(key5);
	$('#unionType_div').val(unionType)
	if(categoryCode!="19002"&&categoryCode!="19003"){
		$("#agentNo_div ~ span").remove(".red");
		$("#protocolNo_div ~ span").remove(".red");
		$("#cbrkrname_div ~ span").remove(".red");
	}else{
		if($("#agentNo_div ~ span").length==0){
			$("#agentNo_div").parent().append("<span class='red'>*</span>");
		}
		if($("#protocolNo_div ~ span").length==0){
			$("#protocolNo_div").parent().append("<span class='red'>*</span>");
		}
		if($("#cbrkrname_div ~ span").length==0){
			$("#cbrkrname_div").parent().append("<span class='red'>*</span>");
		}
	}
	//
	$('#searchPartnerBtn2Code').hide();
	$('#unionType_tr').hide();
	$('#partnerCode_tr').show();
	if(agentTypeFlag == '3'){
		  $('.userAgentMtInfo').show();
		  $('.branchAgentMtInfo').hide();
		  $("#zone_div").val('');
		  $("#brach_div").val('');
		  $("#brachName_div").val('');
		  $("#userCode_div").next().show();
		  $("#userName_div").next().show();
		  $('.Key1AgentMtInfo').hide();
		  $('.Key2AgentMtInfo').hide();
		  $('.Key3AgentMtInfo').hide();
		  $('.Key4AgentMtInfo').hide();
		  $('.Key5AgentMtInfo').hide();
	  }else if(agentTypeFlag == '4'){
		  $('.userAgentMtInfo').hide();
		  $('.branchAgentMtInfo').show();
		  $("#userCode_div").next().hide();
		  $("#userName_div").next().hide();
		  $("#subPartnerCode_div").val('');
		  $('.Key1AgentMtInfo').hide();
		  $('.Key2AgentMtInfo').hide();
		  $('.Key3AgentMtInfo').hide();
		  $('.Key4AgentMtInfo').hide();
		  $('.Key5AgentMtInfo').hide();
	  }else if(agentTypeFlag == '5'){
		  $('.userAgentMtInfo').hide();
		  $('.branchAgentMtInfo').hide();
		  $("#userCode_div").next().hide();
		  $("#userName_div").next().hide();
		  $('.userNameAgentMtInfo').hide();
		  $('.nameAgentMtInfo').hide();
		  $('.Key1AgentMtInfo').show();
		  $('.Key2AgentMtInfo').show();
		  $('.Key3AgentMtInfo').show();
		  $('.Key4AgentMtInfo').show();
		  $('.Key5AgentMtInfo').show();
		  $('#partnerCode_tr').hide();
		  $('#unionType_tr').show();
	  }
	querySauserAndTeamInfo(tempTr);
	$("#addOrUpdateDiv").OpenDiv();
}
//点击“删除”（agentInfo）
function delAgentMtInfo(obj){
	var tempTr = $(obj).parent().parent()[0];
	var agentType = tempTr.childNodes[0].innerHTML;
	var userCode = tempTr.childNodes[2].innerHTML;
	var subChannelCode = tempTr.childNodes[8].innerHTML;
	var channelCode = tempTr.childNodes[6].innerHTML;
	var id = tempTr.childNodes[38].innerHTML;
	var transType = tempTr.childNodes[34].innerHTML;
	var title ="您确定要删除该条记录吗？"
	if('1'== transType && '4'== agentType){
		title = "删除会同步删除记录下的所有出单用户？";
	}
	if(id){
		$.dialog({
			type: "warn",//success,error
			content: title,
			onOk: function() {
				$.openLoading();
				 $.ajax({
						url : "<%=path%>/agentInfoMtManage/deleteAgentMtInfoById?"+new Date().getTime(),
						type : 'POST',
						async: true,
						dataType:'json',
						data:{
							id:id,
							userCode:userCode,
							subChannelCode:subChannelCode,
							agentType:agentType,
							transType:transType,
							channelCode:channelCode
						},
						success : function(data) {
							$.closeLoading();
							if($.validate(data)) return;
							queryAgentMtInfo(1);
						}
					});	 
			}
		});
	}
}

$(document).ready(function(){
	//归属渠道
	$("#channelCodeQD").change(function(){
		var parentCode = $("#channelCodeQD").val();
		subDropDownList("channel_type",parentCode,"channelType");
		subDropDownList("new_business_source","","newBsnsType");
	});
	//渠道类型
	$("#channelType").change(function(){
		var parentCode = $("#channelType").val();
		subDropDownList("new_business_source",parentCode,"newBsnsType");
		if(parentCode==''){
			$("#bsnsType").val('');
		}
	});
	//新业务来源
	$("#newBsnsType").change(function(){
		var parentCode = $("#channelType").val();
		var newBsnsCode = $("#newBsnsType").val();
		chooseBsnsType(parentCode,newBsnsCode);
	});
	//旧业务来源
	$("#bsnsType").change(function(){
		var newBsnsCode = $("#newBsnsType").val();
		var bsnsTypeCode = $("#bsnsType").val();
		//原业务来源为19002-代理或19003-经纪，则代理人代码和代理协议号必填，其他非必填
		if(bsnsTypeCode!="19002"&&bsnsTypeCode!="19003"){
			$("#agentNo_div ~ span").remove(".red");
			$("#protocolNo_div ~ span").remove(".red");
			$("#cbrkrname_div ~ span").remove(".red");
		}else{
			if($("#agentNo_div ~ span").length==0){
				$("#agentNo_div").parent().append("<span class='red'>*</span>");
			}
			if($("#protocolNo_div ~ span").length==0){
				$("#protocolNo_div").parent().append("<span class='red'>*</span>");
			}
			if($("#cbrkrname_div ~ span").length==0){
				$("#cbrkrname_div").parent().append("<span class='red'>*</span>");
			}
		}
	});
});
//下拉框处理
function subDropDownList(codeType,element1,element2,element3){
	$.ajax({
		url : "<%=path%>/agentInfoMtManage/loadSubDropList",
		type : 'POST',
		async : false,
		data:{codeType:codeType,parentCode:element1},
		dataType:'json',
		success:function(appList){
			if($.validate(appList))  return;
			var appSelect = document.getElementById(element2);
			appSelect.options.length = 0;
			if (appList != null) {
				for (var i = 0; i < appList.length; i++) {
					var option = new Option();
					option.text = appList[i].codeName;
					option.value = appList[i].code;
					appSelect.add(option);
				}
			}
       	}
	});
}
//选择旧业务来源
function chooseBsnsType(parentCode,newBsnsCode){
	$.ajax({
		url : "<%=path%>/agentInfoMtManage/chooseBsnsType",
		type : 'POST',
		async : false,
		data:{parentCode:parentCode,newBsnsCode:newBsnsCode},
		dataType:'json',
		success:function(data){
				if($.validate(data))  return;
				if (data != null) {
					$("#bsnsType").val(data.otherCode);
					//原业务来源为19002-代理或19003-经纪，则代理人代码和代理协议号必填，其他非必填
					if(data.otherCode=="19002"||data.otherCode=="19003"){
						if($("#agentNo_div ~ span").length==0){
							$("#agentNo_div").parent().append("<span class='red'>*</span>");
						}
						if($("#protocolNo_div ~ span").length==0){
							$("#protocolNo_div").parent().append("<span class='red'>*</span>");
						}
						if($("#cbrkrname_div ~ span").length==0){
							$("#cbrkrname_div").parent().append("<span class='red'>*</span>");
						}
					}else{
						$("#cbrkrname_div ~ span").remove(".red");
						$("#agentNo_div ~ span").remove(".red");
						$("#protocolNo_div ~ span").remove(".red");
					}
				}
       	}
	});
}


</script>
</head>

<body>
	<div class="current">
           <table class="current_table_1">
              <tbody><tr class="f2">
                <td><img src="./images/current_1.jpg"></td>
                  <td class="current_table_1_td">
                  <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                  <span style=" color:#136bab; ">合作伙伴管理
                  <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>销售渠道信息配置
                  </span>
                  </td>
                  <td><img src="./images/current_3.jpg"></td>
              </tr>
           </tbody></table>
      </div>

	<%--显示user的表格 --%>
	<table border="1" class="table_02" style="height:50px">
  		<tr height="50px">
  			<td>
  				<table  class="search_table">
					<tbody>
					   <tr>
					   		<td>
					   			销售类型 ：&nbsp;<select id="agentType" class="select_1 valid" style="visibility: visible; width: 120px;">
								<c:forEach var="agentTypeList" items="${agentTypeList}">
									<c:if test="${agentTypeList.code ne '1'}">
										<option value="${agentTypeList.code}">${agentTypeList.codeName}</option>
									</c:if>
			        			</c:forEach>
								 </select>&nbsp;
					   		</td>
					   		<td id='channelCode_td'>
					   			合作伙伴代码：
								<input name="txt3"  id="channelCode_1"  type="text" class="input_text" value="" readonly="readonly" style="width: 120px; background-color:#ccc;">
								<input type="button"  class="input_button_1" id="searchPartner" value="选择" onClick="openThisDiv('tradPartnerDiv',1,this,'1')"/>&nbsp;
					   		</td>
					   		 <td>
					   			机构：
								<input name="txt3"  id="deptCode_s"  type="text" class="input_text" value="" readonly="readonly" style="width: 120px; background-color:#ccc;">
								<input type="button"  class="input_button_1" id="searchDeptCode" value="选择" onClick="openDeptDiv1(1,this)"/>&nbsp;
					   		</td>
					   		<td>
					   		业务员代码：
							<input name="txt3" id="empNo_s"  type="text" class="input_text" value="" >&nbsp;  
					   		</td>
					   		<td id='agentNo_td' style="display: none;">
						   		代理人代码：
								<input name="txt3" id="agentNo_s"  type="text" class="input_text" value="" >&nbsp;  
					   		</td>
					   </tr>
					   <tr>
					 		<td>
						   		<span id='branch_td'>网点代码 ：
								<input name="txt3" id="branch_s"  type="text" class="input_text" value="" >&nbsp;  
						   		</span>
						   		<span style="display: none;" id='userCode_td'>
						   			 用户名 ：
									<input name="txt3" id="userCode"  type="text" class="input_text" value="" >&nbsp;
						   		</span>
						   		<span style="display: none;" id='protocolNo_td'>
						   			 代理协议号 ：
									<input name="txt3" id="protocolNo_s"  type="text" class="input_text" value="" >&nbsp;
						   		</span>
						   	</td>
						   	<td >
						   		<span id='branchname_td' style="display:none;">
							   		网点名称：
									<input name="txt3" id="branchName_s"  type="text" class="input_text" value="" >&nbsp;  
					   			</span>
					   			<span id='username_td' style="display:none;">
					   				姓名：
									<input name="txt3" id="userName"  type="text" class="input_text" value="" >&nbsp;							
					   			</span>
					   		</td>
					   		<td colspan="2" >
					   			<input type="button" id="queryFacadeUserBtn" class="input_button_1" value="查询" onclick="queryAgentMtInfo(1)"/>
								<input type="button" id="resetSearchBtn" class="input_button_1"  value="重置" onclick="resetSearch()"/>
								<input type="button" id="addUserBtn" class="input_button_1"  value="新增" onclick="addAgentInfo()"/>	
					   		</td>
					   </tr>
					</tbody>
				</table>
			</td>
  		</tr>
  		<tr>
  			<table border="1" class="table_02" style="height:50px">
	  			<tr>
	  				<td width="29%" nowrap="nowrap"><a href="<%=path%>/agentInfoMtManage/downloadUserTemplet?&templateType=UserAgent" >&nbsp;&nbsp;个人销售渠道信息模板下载&nbsp;</a></td>
	  				<td width="21%" nowrap="nowrap"><input  id="fileToUpload" name="myfiles" type='file' size='20'/><a href="javascript:void(0);" id="buttonUpload">&nbsp;&nbsp;导入个人销售渠道信息&nbsp;&nbsp;</a></td>
	  			  	<td><span class="red">注：导入个人销售渠道信息时，如系统已存在对应用户销售信息，则更新，如不存在，则系统新增对应信息</span></td>
	  			</tr>
	  			<tr>
	  			</tr>
	  			<tr>
	  				<td width="29%" nowrap="nowrap"><a href="<%=path%>/agentInfoMtManage/downloadUserTemplet?&templateType=subBranchAgent">总对总销售渠道信息模板下载</a></td>
	  				<td width="21%" nowrap="nowrap"><input  id="fileToUploadBranch" name="myfiles" type='file' size='20'/><a href="javascript:void(0);" id="buttonSubUpload">导入总对总销售渠道信息</a></td>
	  			  	<td><span class="red">注：导入总对总销售渠道信息时，如系统已存在对应网点销售信息，则更新，如不存在，则系统新增对应信息</span></td>
	  			</tr>
	  			<tr>
	  				<td width="29%" nowrap="nowrap"><a href="<%=path%>/agentInfoMtManage/downloadUserTemplet?&templateType=CombinedAgent">联合出单销售渠道信息模板下载</a></td>
	  				<td width="21%" nowrap="nowrap"><input  id="fileToCombinedUpload" name="myfiles" type='file' size='20'/><a href="javascript:void(0);" id="buttonCombinedUpload">导入联合出单销售渠道信息</a></td>
	  			  	<td><span class="red">注：导入联合出单销售渠道信息时，如系统已存在对应联合出单销售信息，则更新，如不存在，则系统新增对应信息</span></td>
	  			</tr>
	     	</table>
	     	<div style="margin-top:10px;margin-right:35px;text-align: right;color:blue;">注：导入或新增个人销售渠道信息时，会自动创建出单用户、初始密码为个人用户名,服务名称，业务员名称为新意见险必填</div>
  		</tr>
  		</table>
  		<div style="width: 100%;margin:5px;overflow:scroll;">
	  		<table class="table_02" style="width: 3400px;margin:5px">
	  		<tr>
	  			<td align="top">
		  			<div id="userDIV" style="overflow: scroll;">
				  		<table  id="agentInfoTable" >
				  		<thead>
			              <tr>
			                		<th style="width: 2%;">销售类型</th>
									<th style="width: 2%;">用户名</th>
									<th style="width: 2%;">姓名</th>
									<th style="width: 3%;">联合出单方案</th>
									<th style="width: 5%;">合作伙伴</th>
									<th style="width: 6%;">网点名称</th>
									<th style="width: 2%;">出单机构</th>
									<th style="width: 2%;">归属渠道</th>
									<th style="width: 3%;">渠道类型</th>
									<th style="width: 3%;">新业务来源</th>
									<th style="width: 3%;">原业务来源</th>
									<th style="width: 3%;">代理人编码</th>
									<th style="width: 3%;">代理协议号</th>
									<th style="width: 4%;">代理人名称</th>
									<th style="width: 3%;">服务代码</th>
									<th style="width: 6%;">服务名称</th>
									<th style="width: 3%;">业务员代码</th>
									<th style="width: 2%;">业务员名称</th>
									<th style="width: 3%;">单证领用人</th>
									<th style="width: 3%;">团队代码</th>
									<th style="width: 2%;">操作员</th>
									<th style="width: 2%;">Key1</th>
									<th style="width: 2%;">Key2</th>
									<th style="width: 2%;">Key3</th>
									<th style="width: 2%;">Key4</th>
									<th style="width: 2%;">Key5</th>
									<th style="width: 3%;">组织机构代码</th>
									<th style="width: 3.5%;">中介机构许可证号</th>
									<th style="width: 2.5%;">执业证书编号</th>
									<th style="width: 2%;">联系电话</th>
									<th style="width: 3%;">销售/经纪人员</th>
									<th style="width: 3%;">代理人身份证号</th>
									<th style="width: 3%;">销售人员证件号</th>
									<th style="width: 7%">操作</th>
			              </tr>
			              </thead>
			              <tbody>
						  </tbody>
			            </table>
							<div id="agentInfoPageDIV"  class="page" >
		  				 </div>
		  			</div>
	  			</td>
	  		</tr>
	  	</table>
  	</div>
  	<%--添加或修改agentInfo相关数据弹出层 --%>
  	<div id="addOrUpdateDiv" style="display: none;width:600px;height:460px;overflow-y:auto;">
  		<div class="table_title_div">
				<table class="table_title" style='width:100%;height: 20px;'>
					<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="<%=path %>/images/closedown.gif" alt="关闭"  onclick="closeAddOrUpdateDiv()"/></td>
					</tr>
				</table>
		</div>
		
		<table class="table_02" align="center" style="height: 65%;width: 95%" >
			<tr>
				<td style="text-align:right;border-right:0px;" width="40%">销售类型：</td>
				<td style="text-align:left;" width="60%">&nbsp;
					 <select id="agentType_div" class="select_1 valid" style="visibility: visible;">
								<c:forEach var="agentTypeList_div" items="${agentTypeList}">
									<c:if test="${agentTypeList_div.code ne '1'}">
										<option value="${agentTypeList_div.code}">${agentTypeList_div.codeName}</option>
									</c:if>
			        			</c:forEach>
					 </select><span class="red">*</span>
				</td>
			</tr>
			<tr id='partnerCode_tr'>
				<td style="text-align:right;border-right:0px;" width="40%">合作伙伴：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input name="partnerCode_div" id="partnerCode_div" type="text" readonly="readonly" style=" background-color: #ccc;" class="input_text"><span class="red">*</span>&nbsp;<input type="button"  class="input_button_2" id="searchPartnerBtn2Code" value="请选择" onClick="openThisDiv('tradPartnerDiv',1,this,'3')"/>
				</td>
			</tr>
			<tr id='unionType_tr'>
				<td style="text-align:right;border-right:0px;" width="40%">联合出单方案：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<select id="unionType_div" class="select_1 valid" style="visibility: visible;">
						<option value="">-----请选择-----</option>
                  		<c:forEach var ="unionType" items="${unionTypes}">
                  			<option value="${unionType.code}">${unionType.codeName}</option>
                  		</c:forEach>
					 </select><span class="red">*</span>
				</td>
			</tr>
			<tr class = "userNameAgentMtInfo">
				<td style="text-align:right;border-right:0px;" width="40%">用户名：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input id="userCode_div" name="userCode_div" type="text"  maxlength="50" class="input_text"/><span class="red">*</span>
				</td>
			</tr>
			<tr class = "nameAgentMtInfo">
				<td style="text-align:right;border-right:0px;" width="40%">姓名：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input id="userName_div" name="userName_div" type="text" maxlength="100" class="input_text"/><span class="red">*</span>
				</td>
			</tr>
			<tr class = "userAgentMtInfo">
				<td style="text-align:right;border-right:0px;" width="40%">合作伙伴子机构：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input name="subPartnerCode_div" id="subPartnerCode_div" type="text" readonly="readonly" style=" background-color: #ccc;" class="input_text"><span style="padding-left: 10px;"></span>&nbsp;<input type="button" class="input_button_2" id="searchPartnerBtn" value="请选择" onClick="openSubChannelInfoDiv(1,this)"/>
				</td>
			</tr>
			<tr class = "branchAgentMtInfo">
				<td style="text-align:right;border-right:0px;" width="40%">区域代码：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input id="zone_div" name="zone_div" type="text" maxlength="20" class="input_text"/>
				</td>
			</tr>
			<tr class = "branchAgentMtInfo">
				<td style="text-align:right;border-right:0px;" width="40%">组织机构代码：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input id="organization_div" name="organization_div" type="text" maxlength="20" class="input_text"/>
				</td>
			</tr>
			<tr class = "branchAgentMtInfo">
				<td style="text-align:right;border-right:0px;" width="40%">网点代码：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input id="branch_div" name="branch_div" type="text" maxlength="20" class="input_text"/><span class="red">*</span>
				</td>
			</tr>
			<tr class = "branchAgentMtInfo">
				<td style="text-align:right;border-right:0px;" width="40%">网点名称：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input id="branchName_div" name="branchName_div" type="text" maxlength="1000" class="input_text"/><span class="red">*</span>
				</td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="40%">归属渠道：</td>
				<td style="text-align:left;" width="60%">&nbsp;
					 <select id="channelCodeQD" class="select_1 valid" style="visibility: visible;">
						<option value="">-----请选择-----</option>
                  		<c:forEach var ="btcList" items="${btcList}">
                  			<option value="${btcList.code}">${btcList.codeName}</option>
                  		</c:forEach>
					 </select><span class="red">*</span>
				</td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="40%">渠道类型：</td>
				<td style="text-align:left;" width="60%">&nbsp;
					 <select id="channelType" class="select_1 valid" style="visibility: visible;">
						<option value="">-----请选择归属渠道-----</option>
                  		<c:forEach var ="channelList" items="${channelList}">
                  			<option value="${channelList.code}">${channelList.codeName}</option>
                  		</c:forEach>
					 </select><span class="red">*</span>
				</td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="40%">新业务来源：</td>
				<td style="text-align:left;" width="60%">&nbsp;
					 <select id="newBsnsType" class="select_1 valid" style="visibility: visible;">
						<option value="">-----请选择渠道类型-----</option>
                  		<c:forEach var ="newBSList" items="${newBSList}">
                  			<option value="${newBSList.code}">${newBSList.codeName}</option>
                  		</c:forEach>
					 </select><span class="red">*</span>
				</td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="40%">原业务来源：</td>
				<td style="text-align:left;" width="60%">&nbsp;
					 <select id="bsnsType" class="select_1 valid" style="visibility: visible;">
						<option value="">-----请选择-----</option>
                  		<c:forEach var ="oldBSList" items="${oldBSList}">
                  			<option value="${oldBSList.code}">${oldBSList.codeName}</option>
                  		</c:forEach>
					 </select><span class="red">*</span>
				</td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="40%">出单机构：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input id="deptCode_div"  type="text" readonly="readonly" style=" background-color: #ccc;" class="input_text"><span class="red">*</span>&nbsp;<input type="button"  class="input_button_2" id="searchDeptBtn" value="请选择" onClick="openDeptDiv(1,this)"/>
				</td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="40%">业务员代码：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<div id="empNo_select_div" style="display: none">
              			<select id="empNo_select" onchange="changeEmpNo()" class="select_1"></select>
              		</div>
					<input id="empNo_div" name="empNo_div" type="text" maxlength="10" class="input_text"/><span class="red">*</span>&nbsp;<input type="button"  class="input_button_2"  onclick="inputBtn()" value="手动录入" />
				</td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="40%">业务员名称：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input id="empName_div" name="empName_div" type="text" maxlength="20" class="input_text"/><span class="red">*</span>
				</td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="40%">团队代码：</td>
				<td style="text-align:left" width="60%">&nbsp;
					 <div id="teamCode_select_div" style="display: none" >
					 		<select id="teamCode_select" onclick="changeTeamCode()" class="select_1"></select>
					 </div>
					<input id="teamCode_div" name="teamCode_div" type="text" maxlength="11" class="input_text"/><span class="red">*</span>
				</td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="40%">团队名称：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input id="teamName_div" name="teamName_div" type="text" maxlength="300" class="input_text"/><span class="red">*</span>
				</td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="40%">代理人编码：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<div id="agentNo_select_div" style="display: none">
	                  		<select id="agentNo_select" onchange="changeAgentNo()" class="select_1"></select>
	                 </div>
					<input id="agentNo_div" name="agentNo_div" type="text" maxlength="20" class="input_text"/><span class="red">*</span>
				</td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;"  width="40%">代理人协议号：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input id="protocolNo_div" name="protocolNo_div" type="text" maxlength="13" class="input_text"/><span class="red">*</span>
				</td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;"  width="40%">代理人名称：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input id="cbrkrname_div" name="cbrkrname_div" type="text" maxlength="20" class="input_text"/><span class="red">*</span>
				</td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="40%">服务代码：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<div id="serviceCode_select_div" style="display: none">
	                  		<select id="serviceCode_select" onchange="changeServiceCode()" class="select_1"></select>
	                 </div>
					<input id="serviceCode_div" name="serviceCode_div" type="text" maxlength="20" class="input_text"/><span class="red">*</span>
				</td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="40%">服务名称：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input id="serviceName_div" name="serviceName_div" type="text" maxlength="20" class="input_text"/><span class="red">新意健险为必填</span>
				</td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="40%">单证领用人：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input id="cardApplicant_div" name="cardApplicant_div" type="text" maxlength="20" class="input_text"/>
				</td>
			</tr>
			<tr>
				<td style="text-align:right;border-right:0px;" width="40%">操作员：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input id="coprcod_div" name="coprcod_div" type="text" maxlength="300" class="input_text"/>
				</td>
			</tr>
			<tr class = "Key1AgentMtInfo">
				<td style="text-align:right;border-right:0px;" width="40%">Key1：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input id="pro_key1" name="pro_key1" type="text" maxlength="300" class="input_text"/><span class="red">*</span>
				</td>
			</tr>
			<tr class = "Key2AgentMtInfo">
				<td style="text-align:right;border-right:0px;" width="40%">Key2：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input id="pro_key2" name="pro_key2" type="text" maxlength="300" class="input_text"/><span class="red">*</span>
				</td>
			</tr>
			<tr class = "Key3AgentMtInfo">
				<td style="text-align:right;border-right:0px;" width="40%">Key3：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input id="pro_key3" name="pro_key3" type="text" maxlength="300" class="input_text"/>
				</td>
			</tr>
			<tr class = "Key4AgentMtInfo">
				<td style="text-align:right;border-right:0px;" width="40%">Key4：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input id="pro_key4" name="pro_key4" type="text" maxlength="300" class="input_text"/>
				</td>
			</tr>
			<tr class = "Key5AgentMtInfo">
				<td style="text-align:right;border-right:0px;" width="40%">Key5：</td>
				<td style="text-align:left" width="60%">&nbsp;
					<input id="pro_key5" name="pro_key5" type="text" maxlength="300" class="input_text"/>
				</td>
			</tr>
		</table>
		<div align="center">
		   <input type="button" value="保存" onclick="saveAgentMtInfo()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
	       <input type="button" value="取消" onclick="closeAddOrUpdateDiv()" class="input_button_3"/>
		</div>
	</div>
  	<!--选择合作伙伴 div-->
  		<div id="tradPartnerDiv" style="display:none;width:90%;text-align: center;">
		<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('tradPartnerDiv')"/></td>
						</tr>
					</table>
			</div>
		<table class="table_02" id="table" style="width:98%">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="3" style="text-align:center">合作伙伴代码：<input name="txt3"  id="channelCode"  type="text" class="input_text" value="" >
								&nbsp;&nbsp;合作伙伴名称：<input name="txt3" id="channelName"  type="text" class="input_text" value="">
								&nbsp;&nbsp;<input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryTradPartners(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="TradPartnerTable"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:10%">合作伙伴代码</th>
			                  <th style="width:20%">合作伙伴名称</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="TradPartnerPageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center">
		   <input type="button" id="saveRoleBtn" value="确定" onclick="choosePartner()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		   <input type="button" value="取消" onclick="closeCurrentDIV('tradPartnerDiv')" class="input_button_3"/>
		</div>
	</div>
	<!--选择合作伙伴子机构div-->
  		<div id="subTradPartnerDiv" style="display:none;width:90%;text-align: center;">
		<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('subTradPartnerDiv')"/></td>
						</tr>
					</table>
			</div>
		<table class="table_02" id="table" style="width:98%">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="3" style="text-align:center">合作伙伴子机构代码：<input name="txt3"  id="subChannelCode"  type="text" class="input_text" value="" >
								&nbsp;&nbsp;合作伙伴子机构名称：<input name="txt3" id="subChannelName"  type="text" class="input_text" value="">
								&nbsp;&nbsp;<input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="querySubChannelInfo(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="subTradPartnerTable"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:10%">合作伙伴子机构代码</th>
			                  <th style="width:20%">合作伙伴子机构名称</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="subTradPartnerPageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center">
		   <input type="button" id="saveRoleBtn" value="确定" onclick="chooseSubChannelInfo()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		   <input type="button" value="取消" onclick="closeCurrentDIV('subTradPartnerDiv')" class="input_button_3"/>
		</div>
	</div>
	<!--   	机构 DIV 默认隐藏-->
	<div id="deptDiv" style="display:none;width:80%;">
  		<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('deptDiv')"/></td>
						</tr>
					</table>
			</div>
		<table class="table_02" id="table" style="height:180px;" align="center">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="3" style="text-align:center">
							 出单机构代码：<input name="txt3"  id="deptcode"  type="text" class="input_text" value="" >&nbsp;&nbsp;
							 出单机构名称：<input name="txt3" id="deptcnname"  type="text" class="input_text" value="">
								       <input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryCoreDept(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="deptTable"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:45%">出单机构代码</th>
			                  <th style="width:50%">出单机构名称</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="deptPageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center" >
		  <input type="button" id="saveRoleBtn" value="确定" onclick="chooseDept()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		  <input type="button" value="取消" onclick="closeCurrentDIV('deptDiv')" class="input_button_3"/>
		</div>
	</div>	
	<!--广东分公司配置销售人员信息div-->
  	<div id="sale_div" style="display:none;width:1000px; height:450px;">
		<div class="table_title_div" style="width: 990px">
			<table class="table_title" style='width:990px;height: 20px;'>
				<tr>
				<td width="220px" style="font-weight: bold; padding-left: 5px">财险销售信息配置</td>
				<td width="1360px" id="interfaceName"></td>
				<td width="60px" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeNocarAgentTypeDiv('sale_div')"/></td>
				</tr>
			</table>
		</div>
		<table class="table_02" id="table" style="width:990px;" align="center">
			<tr>
				<td>
					<table id="sale3"  class="content_table_1">
						<thead>
							<tr class="f1">
			               	  <th style="width:90px">序号</th>
			                  <th style="width:110px">销售员类型<span style="margin-left: -5px" class="red">*</span></th>
			                  <th style="width:90px">费用比例<span style="margin-left: -5px" class="red">*</span></th>
			                  <th style="width:90px">执业证号</th>
			                  <th style="width:90px">人员类别<span style="margin-left: -5px" class="red">*</span></th>
			                  <th style="width:90px">销售员</th>
			                  <th style="width:90px">业务员<span style="margin-left: -5px" class="red">*</span></th>
			                  <th style="width:90px">代理人编号</th>
			              	</tr>
						</thead>
						<tbody id='salecontent'>
						</tbody>
					</table>
				</td>
			</tr>
		</table>
		<div class="table_title_div" style="width: 990px">
			<table class="table_title" style='width:990px;height: 20px;'>
				<tr>
				<td width="220px" style="font-weight: bold; padding-left: 5px">新意健险销售信息配置</td>
				<td width="1360px" ></td>
				<td width="60px" align="right"></td>
				</tr>
			</table>
		</div>
		<table class="table_02" id="table1" style="width:990px;" align="center">
			<tr>
				<td>
					<table id="sale4"  class="content_table_1">
						<thead>
							<tr class="f1">
			               	  <th style="width:90px">序号</th>
			                  <th style="width:110px">销售员类别<span style="margin-left: -5px" class="red">*</span></th>
			                  <th style="width:90px">销售人员代码<span style="margin-left: -5px" class="red">*</span></th>
			                  <th style="width:90px">销售人员名称</th>
			                  <th style="width:90px">执业证号</th>
			                  <th style="width:90px">代理机构号</th>
			                  <th style="width:90px">代理人机构名称</th>
			                  <th style="width:90px">分摊比例<span style="margin-left: -5px" class="red">*</span></th>
			              	</tr>
						</thead>
						<tbody id='salecontent4'>
						</tbody>
					</table>
				</td>
			</tr>
		</table>
		<div align="center" >
		  <input type="button" id="saveSaleBtn" value="保存" onclick="saveSale()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		  <input type="button" value="取消" onclick="closeNocarAgentTypeDiv('sale_div')" class="input_button_3"/>
		</div>
		<input type="hidden" id="agentId" value=""/>
	</div>
	<!--   	机构 DIV 默认隐藏-->
	<div id="deptDiv1" style="display:none;width:80%;">
  		<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeSearchDeptDiv()"/></td>
						</tr>
					</table>
			</div>
		<table class="table_02" id="table" style="height:180px;" align="center">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="3" style="text-align:center">
							机构代码：<input name="txt3"  id="deptcode1"  type="text" class="input_text" value="" >&nbsp;&nbsp;
							 机构名称：<input name="txt3" id="deptcnname1"  type="text" class="input_text" value="">
								       <input type="button"  class="input_button_1" id="searchBtn1" value="查询" onClick="queryCoreDept1(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="deptTable1"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:45%">机构代码</th>
			                  <th style="width:50%">机构名称</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="deptPageDIV1"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center" >
		  <input type="button" id="saveRoleBtn1" value="确定" onclick="chooseDept1()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		  <input type="button" value="取消" onclick="closeSearchDeptDiv()" class="input_button_3"/>
		</div>
		</div>
		<!-- 方案配置div -->
		<div id="planDiv" style="display:none;width:90%;">
	  		<input type="hidden" id="row_num" name="row_num" value="0"/>
				<div class="table_title_div">
						<table class="table_title" style='width:100%;height: 20px;'>
							<tr>
							<td width="10%"></td>
							<td width="80%"></td>
							<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closePlanDeptDiv()"/></td>
							</tr>
						</table>
				</div>
			<table class="table_02" id="table" style="height:180px;" align="center">
				<tr height="30px">
					<td>
						<table class="search_table">
							<tr height="30px">
								<td colspan="3" style="text-align:center">
								方案号：<input name="txt3"  id="planNo"  type="text" class="input_text" value="" >&nbsp;&nbsp;
								 方案名称：<input name="txt3" id="planName"  type="text" class="input_text" value="">
								分公司：<select id="deptCode_p" class="select_1 valid" style="visibility: visible; width: 120px;">
											<c:forEach var="branch" items="${branchList}">
												<option value="${branch.deptCode}">${branch.deptCname}</option>
						        			</c:forEach>
								 		</select>
								<input type="button"  class="input_button_1" id="plansearchBtn" style="margin-left: 5px" value="查询" onClick="planFeeParam(1)"/>
								<input type="button"  class="input_button_1" id="resetBranch" style="margin-left: 5px" value="重置" onClick="planFeeReset()"/>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<table id="planTable"  class="content_table_1">
							<thead>
								<tr class="f1">
				                  <th style="width:60px"><input type="checkbox" id="auwConfigCheckAll" ></th>
				                  <th>方案号</th>
				                  <th style="width:150px">方案名称</th>
				                  <th style="width:100px">分公司</th>
				                  <th>合作伙伴</th>
				                  <th>车险车辆类型</th>
				                  <th>意健险车辆性质</th>
				                  <th style="width:80px">手续费比例</th>
				                  <th style="width:80px">业务绩效比例</th>
				                  <th style="width:80px">市场维护费比例</th>
				              	</tr>
							</thead>
							<tbody>
							<tr>
							</tr>
							</tbody>
						</table>
						<div id="planPageDIV"  class="page"></div>
					</td>
				</tr>
			</table>
			<div align="center" >
			  <input type="button" id="saveRoleBtn1" value="确定" onclick="choosePlanFee()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
			  <input type="button" value="取消" onclick="closePlanDeptDiv()" class="input_button_3"/>
			</div>
			<!-- 方案配置div结束 -->
	</div>
</body>
</html>
